您好,我有一个用于注册页面的存储过程,但我需要 ADO.NET 从各种文本框中获取值。但是,我收到这样的错误:
“System.ArgumentException:不存在从对象类型 System.Web.UI.WebControls.TextBox 到已知托管提供程序本机类型的映射。”
public void InsertInfo()
{
String empdb = @"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=True";
SqlConnection conn = new SqlConnection(empdb);
SqlCommand cmd = new SqlCommand("bridge_Type", conn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
conn.Open();
cmd.Parameters.Add(new SqlParameter("@EmpID", TextBox1.Text));
cmd.Parameters.Add(new SqlParameter("@Name", TextBox2.Text));
cmd.Parameters.Add(new SqlParameter("@Mob2", TextBox3.Text));
cmd.Parameters.Add(new SqlParameter("@Email", TextBox14.Text));
cmd.Parameters.Add(new SqlParameter("@Emptype", dropdown1.SelectedValue));
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
if (conn != null)
{
conn.Close();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
InsertInfo();
}
然后我使用这种格式从控件中添加值:
cmd.Parameters.Add(new SqlParameter("@EmpID", SqlDbType.Int));
cmd.Parameters("@EmpID").Value = TextBox1.Text;
我收到以下错误:
Its showing errors for these kind of codes by appearing red line under 'Parameters'.
Non-invocable member 'System.Data.SqlClient.SqlCommand.Parameters' cannot be used like a method.