Am new to programming, so please assist as much as possible!
Recently, im tasked to do a CRUD windows form application using C# & MS access.
In my update function, i face one of the following errors which im not sure why..
My data are not able to be updated either.
Error: ArgumentException was unhandled
Input string was not in a correct format.Couldn’t store
in staff_id Column. Expected type is
Int32.
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AcuzioSapp.AcuzioSecureStore_DatabaseDataSetTableAdapters;
namespace AcuzioSapp
{
public partial class Update_Client : Form
{
private DataRow row;
private ClientTableAdapter adapter;
public Update_Client(DataRow row, ClientTableAdapter adapter)
{
InitializeComponent();
this.row = row;
this.adapter = adapter;
textBox_id1.Text = Convert.ToString(row["c_id"]);
textBox_name1.Text = Convert.ToString(row["c_name"]);
textBox_address1.Text = Convert.ToString(row["c_address"]);
textBox_cinfo1.Text = Convert.ToString(row["c_contactinfo"]);
textBox_pinfo1.Text = Convert.ToString(row["profile_info"]);
textBox_refno1.Text = Convert.ToString(row["c_8digitrefno"]);
textBox_staffid1.Text = Convert.ToString(row["staff_id"]);
}
private void button_close_Click(object sender, EventArgs e)
{
Close();
}
private void button_update_Click(object sender, EventArgs e)
{
row["c_name"] = "textBox_name1";
row["c_address"] = "textBox_address1";
row["c_contactinfo"] = "int.Parse(textBox_cinfo1)";
row["c_8digitrefno"] = "(textBox_pinfo1)";
row["profile_info"] = "textBox_refno1";
row["staff_id"] = "int.Parse(textBox_staffid1)";
adapter.Update(row);
}
}
}
Appreciated for help and explanation thankyou.
Thats because of your column is declared integer in your Access database and you try to insert a String value in it. And I also think you will not get proper value in your specified table because you update your columns by constant string
(row["profile_info"] = "textBox_refno1";), this will insert textBox_refno1 intoprofile_infocolumn not TextBox value.Try this :
Update:
Copy and paste following code, and you will never have any issue:
Hope this help.