【发布时间】:2023-03-18 16:58:01
【问题描述】:
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = conn;
command.CommandText = "INSERT INTO myTbl ([username],[password],[firstname],[lastname],[mi],[age],[place],[contact])VALUES (?,?,?,?,?,?,?,?)";
command.Parameters.Add("@user", OleDbType.VarChar).Value = txtUsername.Text;
command.Parameters.Add("@psw", OleDbType.VarChar).Value = txtPassword.Text;
command.Parameters.Add("@nm", OleDbType.VarChar).Value = txtName.Text;
command.Parameters.Add("@Lname", OleDbType.VarChar).Value = txtLastName.Text;
command.Parameters.Add("@mIni", OleDbType.VarChar).Value = txtMI.Text;
command.Parameters.Add("@ag", OleDbType.Integer).Value = Convert.ToInt32(txtAge.Text);
command.Parameters.Add("@plc", OleDbType.VarChar).Value = txtPlace.Text;
command.Parameters.Add("@cntct", OleDbType.Integer).Value = Convert.ToInt32(txtContact.Text); ;
command.ExecuteNonQuery();
lblInfo.Visible = true;
lblInfo.Text = "Success";
conn.Close();
这给了我错误Input string was not in a correct format。请帮帮我。
【问题讨论】:
-
这段代码给了我错误,输入字符串的格式不正确。所以请帮帮我。提前致谢
-
通过调试器运行它,哪一行给出了错误?
-
另外,看看
Int32.TryParse(msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx) 作为Convert.ToInt32的替代品。 -
您能否分享您传递给执行任务的那些值,并且您发现“输入字符串格式不正确”的错误
-
调试并检查你在哪一行得到错误
标签: c# asp.net ms-access insert numeric