protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da1 = new SqlDataAdapter();
DataSet ds1 = new DataSet();
cn.ConnectionString = @"Data Source=BOPSERVER;Initial Catalog=Project;Integrated Security=True";
cn.Open();
string n = Convert.ToString(txtfid.Text);
cmd.CommandText = "select * from Personal_det where FID=" + n + "";
cmd.CommandType = CommandType.Text;
cmd.Connection = cn;
da1.SelectCommand = cmd;
da1.Fill(ds1, "Personal_det");
double dn = ds1.Tables["Personal_det"].Rows.Count;
if (dn == 0)
{
DateTime sdt = DateTime.Today;
SqlCommand cmd3 = new SqlCommand();
cn.Close();
cn.Open();
cmd3.CommandText = "insert into Personal_det(FID,Name,DOB,MobileNo,EmailId,add1,add2,add3,Pincode) values(@FID,@Name,@DOB,@MobileNo,@EmailId,@add1,@add2,@add3,@Pincode)";
cmd3.CommandType = CommandType.Text;
cmd3.Connection = cn;
cmd3.Parameters.Add("@FID", SqlDbType.VarChar,50);
cmd3.Parameters["@FID"].Value = this.txtfid.Text;
cmd3.Parameters.Add("@Name", SqlDbType.VarChar, 50);
cmd3.Parameters["@Name"].Value = this.txtname.Text;
cmd3.Parameters.Add("@DOB", SqlDbType.DateTime, 8);
cmd3.Parameters["@DOB"].Value = Convert.ToDateTime(this.txtdob.Text);
cmd3.Parameters.Add("@MobileNo", SqlDbType.Decimal, 18);
cmd3.Parameters["@MobileNo"].Value = this.txtmbl.Text;
cmd3.Parameters.Add("@EmailId", SqlDbType.VarChar, 50);
cmd3.Parameters["@EmailId"].Value = this.txtmail.Text;
cmd3.Parameters.Add("@add1", SqlDbType.VarChar, 50);
cmd3.Parameters["@add1"].Value = this.txtadd1.Text;
cmd3.Parameters.Add("@add2", SqlDbType.VarChar, 50);
cmd3.Parameters["@add2"].Value = this.txtadd2.Text;
cmd3.Parameters.Add("@add3", SqlDbType.VarChar, 50);
cmd3.Parameters["@add3"].Value = this.txtadd3.Text;
cmd3.Parameters.Add("@Pincode", SqlDbType.Decimal, 18);
cmd3.Parameters["@Pincode"].Value = this.txtpin.Text;
cmd3.ExecuteNonQuery();
cn.Close();
这是我的 C# 代码..实际上我所做的是以前我将 FID 转换为 int 现在我将其转换为 varchar(50),由于某些需要,我已经更改了 sql 中的数据类型..Personal_det 是其中的表FID 是其他表的主键约束和外键..现在当我要执行代码时..它给出了图像中显示的错误