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
。請幫助我。插入數字記錄到ms訪問從c#asp.net
此代碼給我錯誤,輸入字符串格式不正確。所以請幫助我。在此先感謝 – user1337815 2012-04-17 05:03:05
運行它通過調試器,哪一行給出錯誤? – 2012-04-17 05:06:41
另外,請查看'Int32.TryParse'(http://msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx)作爲'Convert.ToInt32'的替代方法。 – 2012-04-17 05:10:59