enter image description here enter image description here我尝试将数据插入MS Access数据库。我的桌子名称是SignUp。
cmd.Parameters.Add("@name", OleDbType.VarChar).Value = txtNameSignUp.Text;
cmd.Parameters.Add("@surname", OleDbType.VarChar).Value = txtSurnameSignUp.Text;
cmd.Parameters.Add("@phone", OleDbType.VarChar).Value = txtPhoneSignUp.Text;
cmd.Parameters.Add("@mail", OleDbType.VarChar).Value = txtMailSignUp.Text;
cmd.Parameters.Add("@address", OleDbType.VarChar).Value = txtAddressSignUp.Text;
cmd.Parameters.Add("@username", OleDbType.VarChar).Value = txtUserNameSignUp.Text;
cmd.Parameters.Add("@password", OleDbType.VarChar).Value = txtPasswordSignUp.Text;
cmd.ExecuteNonQuery();
cnn.Close();
cnn = null;
我尝试(OleDBType.Binary).Value = Convert.ToByte(txtPhoneSignUp.Text);
用于手机的文本框但后来却说“太大”或“太小”。
sorgu =“插入SignUp ([名],[姓氏],[电话],[邮件],[地址],[用户名],[密码]) 值(@ name,@ surname,@ phone,@ mail,@ address,@ username,@ password);“; cmd = new OleDbCommand(sorgu,cnn);
//cmd.Parameters.AddWithValue("@name", txtNameSignUp.Text); //cmd.Parameters.AddWithValue("@surname", txtSurnameSignUp.Text); //cmd.Parameters.AddWithValue("@phone", Convert.ToDouble(txtPhoneSignUp.Text)); //cmd.Parameters.AddWithValue("@mail", txtMailSignUp.Text); //cmd.Parameters.AddWithValue("@address", txtAddressSignUp.Text); //cmd.Parameters.AddWithValue("@username", txtUserNameSignUp.Text); //cmd.Parameters.AddWithValue("@password", txtPasswordSignUp.Text); cmd.Parameters.Add("@name", OleDbType.VarChar).Value = txtNameSignUp.Text; cmd.Parameters.Add("@surname", OleDbType.VarChar).Value = txtSurnameSignUp.Text; cmd.Parameters.Add("@phone", OleDbType.VarChar).Value = cmd.Parameters.Add("@mail", OleDbType.VarChar).Value = txtMailSignUp.Text; cmd.Parameters.Add("@address", OleDbType.VarChar).Value = txtAddressSignUp.Text; cmd.Parameters.Add("@username", OleDbType.VarChar).Value = txtUserNameSignUp.Text; cmd.Parameters.Add("@password", OleDbType.VarChar).Value = txtPasswordSignUp.Text; cmd.ExecuteNonQuery(); cnn.Close(); cnn = null;
答案 0 :(得分:0)
对于OleDBType.Binary,您需要一个byte [],因此请将代码更改为
Encoding.ASCII.GetBytes(txtPhoneSignUp.Text)