field is too small?

Ugojallas

Member
Joined
Apr 5, 2012
Messages
12
Programming Experience
Beginner
i try to insert data into Access with this code but can't it gives me error message pointing at the int n = cmd.ExecuteNonQuery()(the field is too small to accept the amount of data you attempted to add. try inserting or pasting less data)


private void butInsert_Click(object sender, EventArgs e)

{
cmd = new OleDbCommand("insert into books values(" + txtIsdn.Text + ",' " + txtTitle.Text + " ',' " + txtAuthor.Text +
" ',' " + txtPublisher.Text + " ',' " + txtSubject.Text + " ',' " + txtShelf.Text + " ',' " + txtFiction.Text + " ')", con);
con.Open();
int n = cmd.ExecuteNonQuery();
con.Close();

if (n > 0)
{
MessageBox.Show("Record inserted");
loaddata();
}
else

MessageBox.Show("insertion failed");


pls someone should help me out
 
The fact that you're programming doesn't mean that you should leave common sense behind. If you had a jug containing water and you poured it into a glass and it spilled over the sides, would you need someone to help you figure out how to fix that? I certainly hope not. Obviously you need to either use a bigger glass or pour less water into it. That's common sense, right? So why is it that the error message here tells you specifically that that is what you're doing with your data and common sense doesn't tell you the same thing? Use a bigger field or less data. It's that simple.

Also, don't use string concatenation to insert values into SQL code. Always use parameters. To learn why and how, follow the Blog link in my signature and check out my post on Parameters In ADO.NET.
 
Back
Top Bottom