【发布时间】:2016-02-18 01:12:20
【问题描述】:
我想从表单中收集用户输入并将其发送到数据库。我不知道如何告诉sqlCmd.Parameters.Add 使用函数顶部的 x、y 和结果整数。
public void UploadDB_Click(object sender, EventArgs e)
{
int x = ConvertX(sender);
int y = ConvertY(sender);
int result = ConvertResult(sender);
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = @"Data Source=(LocalDb)\v11.0;AttachDbFilename=E:\Dropbox\GridViewSandbox-20160215081718.mdf;Initial Catalog=aspnet-GridViewSandbox-20160215081718;Integrated Security=True";
SqlCommand sqlCmd = new SqlCommand("Procudure1", sqlCon); //can't spell typo :|
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add(new SqlParameter(@"x", SqlDbType.Int)); //the x int should go in here somehow?
sqlCmd.Parameters.Add(new SqlParameter(@"y", SqlDbType.Int)); //the y int
sqlCmd.Parameters.Add(new SqlParameter(@"result", SqlDbType.Int)); //the result int
sqlCon.Open();
sqlCmd.ExecuteNonQuery();
sqlCon.Close();
}
【问题讨论】:
标签: c# sql asp.net visual-studio