This is what I have done:
protected void btnsave_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=user-ade4de77d3;Initial Catalog=test;Persist Security Info=True;uid=sa;pwd=sql2008");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = ("INSERT into person VALUES (@empid,@name,@sex,@mstatus,@empstat,@dob,@doh,@dor,@dot)");
cmd.Parameters.AddWithValue("@empid", txtid.Text);
cmd.Parameters.AddWithValue("@name", txtnam);
cmd.Parameters.AddWithValue("@sex", dpsex.SelectedValue);
cmd.Parameters.AddWithValue("@mstatus", dpmstat.SelectedValue);
cmd.Parameters.AddWithValue("@empstat", dpstatus.SelectedValue);
cmd.Parameters.AddWithValue("@dob", txtdob.Text );
cmd.Parameters.AddWithValue("@doh", txtdoh.Text );
cmd.Parameters.AddWithValue("@dor", txtdor.Text );
cmd.Parameters.AddWithValue("@dot", txtdot.Text );
cmd.ExecuteNonQuery();
con.Close();
}
I’m getting an error like this:
No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type.
How do I clear this error?
You need to change the following line:
as your version is missing the
.Textoff the end.