阅读背景:

数据未使用Windows应用程序插入数据库,但未显示任何错误

来源:互联网 

Button Click Code

按钮单击代码

    String cs = null;
    SqlConnection scon = null;
    SqlCommand cmd = null;
    private void btnOk_Click(object sender,EventArgs e)
    {
            String name = txtBoxName.Text.ToString();
            String mobile = txtBoxMobile.Text.ToString();
            String address = txtBoxAddress.Text.ToString();
            String ty = null;
            if (radioButtonCow.Checked)
            {
                ty = radioButtonCow.Text.ToString();
            }
            else {
                ty = radioButtonBuffalo.Text.ToString();
            }
            int n = 0;
            using(scon = new SqlConnection(cs)){
                scon.Open();
                String query = "insert into new_customer(name,mobile,address,type) 
           values('" + name + "','" + mobile + "','" + address + "','" + ty + "')";
                cmd = new SqlCommand(query, scon);
                n = cmd.ExecuteNonQuery();
            }
        }
        private void NewCustomer_Load(object sender, EventArgs e)
        {
            cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
        }
   }
    String cs = nu



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: