hey friends , i m not being able to save the updates in datagrid view when i press buttonsave_ gridview i have a class customer with two methods one to get the dataset and other to update database:
i dont know what is the problem with my code.
i always get UPDATE syntax run time error, as i press button_save_grod view :
please help me.
my code goes like this: - public class customer
-
{
-
// private static string strConn;
-
-
private static DataTable ds;
-
-
-
public DataTable getdataset(string fname, DataGridView dg)
-
{
-
OleDbConnection con = new OleDbConnection(@"provider= Microsoft.Jet.OLEDb.4.0; Data Source = D:\My Documents\Visual Studio 2005\Projects\db2.mdb");
-
con.Open();
-
-
OleDbDataAdapter thisadapter1 = new OleDbDataAdapter("Select * from tbl_client where fname= '" + fname + "'", con);
-
//OleDbCommandBuilder cd = new OleDbCommandBuilder(thisadapter1);
-
ds = new DataTable();
-
thisadapter1.Fill(ds);
-
-
dg.BringToFront();
-
dg.Visible = true;
-
BindingSource bsource = new BindingSource();
-
bsource.DataSource = ds;
-
dg.DataSource = bsource;
-
dg.Columns[0].Visible = false;
-
dg.Columns[1].Visible = false;
-
dg.Columns[2].HeaderText = "Fname";
-
dg.Columns[2].Width = 45;
-
dg.Columns[3].HeaderText = "Lname";
-
dg.Columns[3].Width = 45;
-
dg.Columns[5].HeaderText = "Gender";
-
dg.Columns[5].Width = 46;
-
dg.Columns[6].HeaderText = "Address";
-
dg.Columns[6].Width = 48;
-
dg.Columns[4].Visible = false;
-
dg.Columns[7].HeaderText = "Phone";
-
dg.Columns[7].Width = 45;
-
dg.Columns[8].HeaderText = "Mobile";
-
dg.Columns[8].Width = 45;
-
dg.Columns[9].HeaderText = "Email";
-
dg.Columns[9].Width = 45;
-
dg.Columns[10].HeaderText = "Project_ID";
-
dg.Columns[10].Width = 55;
-
dg.Columns[11].HeaderText = "Visit Date";
-
dg.Columns[11].Width = 55;
-
dg.Columns[12].HeaderText = "Agent";
-
dg.Columns[12].Width = 45;
-
dg.Columns[13].HeaderText = "FeedBack";
-
dg.Columns[14].HeaderText = "Remarks";
-
string feedback = "FeedBack";
-
dg.Columns[13].HeaderText = feedback;
-
-
return ds;
-
-
}
-
-
-
public int update()
-
{
-
OleDbConnection con = new OleDbConnection(@"provider= Microsoft.Jet.OLEDb.4.0; Data Source = D:\My Documents\Visual Studio 2005\Projects\db2.mdb");
-
con.Open();
-
-
string sqlUpdate;
-
sqlUpdate = "Update tbl_client Set date= @p2, fname=@p3, lname= @p4, mname= @p5, gender= @p6, address= @p7, phone= @p8, mobile=@p9, email=@p10, project_id= @p11, visit_date= @p12, agent= @p13, feetdback1= @p14, remarks= @p15 Where client_id= '@p1'";
-
OleDbParameter[] pUpdate = new OleDbParameter[15];
-
-
-
pUpdate[0] = new OleDbParameter("@p1", OleDbType.VarChar, 40,"client_id");
-
pUpdate[1] = new OleDbParameter("@p2", OleDbType.DBDate, 30, "date");
-
pUpdate[2] = new OleDbParameter("@p3", OleDbType.VarChar, 40,"fname");
-
pUpdate[3] = new OleDbParameter("@p4", OleDbType.VarChar, 20,"lname");
-
pUpdate[4] = new OleDbParameter("@p5", OleDbType.VarChar, 20,"mname");
-
pUpdate[5] = new OleDbParameter("@p6", OleDbType.VarChar, 40, "gender");
-
pUpdate[6] = new OleDbParameter("@p7", OleDbType.VarChar, 40, "address");
-
pUpdate[7] = new OleDbParameter("@p8", OleDbType.Numeric, 9, "phone");
-
pUpdate[8] = new OleDbParameter("@p9", OleDbType.Numeric, 9, "mobile");
-
pUpdate[9] = new OleDbParameter("@p10", OleDbType.VarChar, 40, "email");
-
pUpdate[10] = new OleDbParameter("@p11", OleDbType.VarChar, 40, "project_id");
-
pUpdate[11] = new OleDbParameter("@p12", OleDbType.Date, 40, "visit_date");
-
pUpdate[12] = new OleDbParameter("@p13", OleDbType.VarChar, 40, "agent");
-
pUpdate[13] = new OleDbParameter("@p14", OleDbType.VarChar, 40, "feedback1");
-
pUpdate[14] = new OleDbParameter("@p15", OleDbType.VarChar, 30, "remarks");
-
-
OleDbCommand cmdUpdate = new OleDbCommand(sqlUpdate,con);
-
// cmdUpdate.Parameters.AddRange(pUpdate);
-
-
-
OleDbDataAdapter da = new OleDbDataAdapter();
-
da.UpdateCommand = cmdUpdate;
-
int i=da.Update(ds);
-
ds.AcceptChanges();
-
if(i>0)
-
{
-
MessageBox.Show("database updated");
-
}
-
return i;
-
}
-
-
-
}
thanks in advance
Radhika
1 1721
This wouldn't have something to do with the client_id. Why is the parameter is sngle quotes and why isn't it an integer?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: EMW |
last post by:
How can I put everything that is in a datagrid into a SQL server database
(which should be readable by an PocketPC program)?
There is probably a simple solution for it, but as always it is...
|
by: Bill C. |
last post by:
Hello,
I know this has been discussed a lot already because I've been searching
around for information the last few weeks.
I'm trying to implement a DataGridComboBoxColumn class. I've found...
|
by: Ajay Krishnan Thampi |
last post by:
I have a slight problem implementing 'drag and drop' from a datagrid
to a tree-view. I have pasted my code below. Someone please advice me
on what to do...pretty blur right now.
==code==
...
|
by: sdbranum |
last post by:
I have been using Visual C#.NET to code a large project having many data
adapters, data sets, datagrids, multiple forms with tab pages, each
containing various controls (mostly label, text boxes,...
|
by: CM Manager via DotNetMonster.com |
last post by:
I am very frustrated due to this exception error I am receiving. I've tried
searching numerous user support groups, Microsoft Support Net, Google, etc.
and haven't found exactly my situation....
|
by: Stephen Plotnick |
last post by:
I'm very new to VB.NET 2003
Here is what I have accomplished:
MainSelectForm - Selects an item
In a public class I pass a DataViewRow to
ItemInformation1 Form
ItemInformation2 Form
|
by: Patty05 |
last post by:
I have a datagrid on a form that update properly when form loads. When the program runs and I type in/add a new row in the datagrid, it does not save the changes. Any help would be greatly...
|
by: preethamsaroja |
last post by:
can anybody plz tell m -whats the error in the code for update button in datagrid-where table name is "table1"its has fields "ID","Name","Age","Sex","Area"..
when compiled, its giving error has::...
|
by: =?Utf-8?B?TUNN?= |
last post by:
I'm sure the answer to my question varies depending on the situation, but I
am looking for a general "best practice".
If I have an asp.net application and I load certain data from a database,...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |