myCommand.CommandText="INSERT INTO product(code,address)VALUES('"+Text1.Value+"','"+Text2.Value+"')";

解决方案 »

  1.   

    用存储过程。
    Create procedure insoperation
    (@code varchar(20),
    @address varchar(50))
    as
    INSERT INTO product(code,address)VALUES(@code,@address)然后在程序里面操作是这样的。
    private void insoperation(string str1,string str2)
    {
    SqlConnection cn=new SqlConnection(ConnectString);
    SqlCommand cmd=new SqlCommand("insoperation",cn)
    cmd.CommandType=CommandType.StoredProcedure;
    cn.Open();
    SqlParameter param=cmd.Parameters.Add("@code");
    param["@code"].Value=str1;
    SqlParameter param=cmd.Parameters.Add("@address");
    param["@address"].Value=str2;
    cmd.ExecuteNonQuery();
    }
    当然如果你不想用存储过程,可以直接在界面层的某一button_click中写:
    SqlConnection cn=new SqlConnection(ConnectString);
    SqlCommand cmd=new SqlCommand("insert into product(code,address) values('"+txt1.Text+"','"+txt2.Text+"')",cn);
    cmd.CommandType=CommandType.CommandText;
    cn.Open();
    cmd.ExecuteNonQuery();