下边给出代码:
 1、class sqlHelper
    {
        private static string Coonstr = ConfigurationManager.ConnectionStrings["dbConnstr"].ConnectionString;
        public static int ExecuteNonQuery(string sql, params SqlParameter[] parameter)
        {
            using (SqlConnection conn = new SqlConnection(Coonstr))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    cmd.Parameters.AddRange(parameter);
                    return cmd.ExecuteNonQuery();
                }
            }
        }
2、在下边代码中调用sqlHelper中的ExecuteNonQuery public partial class Dbnull : Window
    {
        public Dbnull()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string username = txtname.Text;
            string userage = txtage.Text;
            string height = txtHeight.Text;
            sqlHelper.ExecuteNonQuery(@"insert into users (userName,userage,Height)",
                new SqlParameter("@userName",username),
                new SqlParameter("@userage",username),
                new SqlParameter("@Height",height));
        }
    } ExecuteNonQuery SQL

解决方案 »

  1.   

    sqlHelper.ExecuteNonQuery(@"insert into users (userName,userage,Height) values(@userName,@userage,@Height)",
      

  2.   


     SqlHelper.ExecuteNonQuery(@"insert into users (userName,userage,Height) VALUES(@userName, @userage,@Height);",
                    new SQLiteParameter("@userName", username),
                    new SQLiteParameter("@userage", userage),
                    new SQLiteParameter("@Height", height));
      

  3.   

    try{
    //your code
    }catch(Exception ex){
    MsgBox.show(ex.Message);
    }查看具体错误信息,开发环境错误信息你不看,让大家猜有什么好猜的