通过SqlConnection使用insert语句时出错

时间:2016-11-21 05:59:09

标签: c# mysql visual-studio

我正在尝试发送一个insert语句,但它在我的连接字符串上抛出一个错误。 “System.Data.dll中出现了'System.ArgumentException'类型的未处理异常”

using (SqlConnection conn = new SqlConnection("server=***.us-west-2.rds.amazonaws.com;port=***;user id=***;database=***;allowuservariables=True;password=***;persistsecurityinfo=True"))
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.Connection = conn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = @"INSERT INTO Member(FName,LName,PhoneNumber,Email,MemberType) 
                        VALUES(@param1,@param2,@param3,@param4,@param5)";

                cmd.Parameters.AddWithValue("@param1", txtFirstName.Text);
                cmd.Parameters.AddWithValue("@param2", txtLastName.Text);
                cmd.Parameters.AddWithValue("@param3", txtPhoneNum.Text);
                cmd.Parameters.AddWithValue("@param4", txtEmail.Text);
                cmd.Parameters.AddWithValue("@param5", cboMemType.Text);

                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch 
                {
                    MessageBox.Show("Error");
                }

            }
        }

0 个答案:

没有答案