473,396 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C#+ Database Update Through The Datagrid View+ Windows Forms+ Very Urgent

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:

Expand|Select|Wrap|Line Numbers
  1. public class customer
  2. {
  3.   // private static string strConn;
  4.  
  5.         private static DataTable ds;
  6.  
  7.  
  8.    public  DataTable getdataset(string fname, DataGridView dg)
  9.    {
  10.         OleDbConnection con = new OleDbConnection(@"provider= Microsoft.Jet.OLEDb.4.0; Data Source = D:\My Documents\Visual Studio 2005\Projects\db2.mdb");
  11.         con.Open();
  12.  
  13.         OleDbDataAdapter thisadapter1 = new OleDbDataAdapter("Select * from tbl_client where fname= '" + fname + "'", con);
  14.         //OleDbCommandBuilder cd = new OleDbCommandBuilder(thisadapter1);
  15.         ds = new DataTable();
  16.         thisadapter1.Fill(ds);
  17.  
  18.         dg.BringToFront();
  19.         dg.Visible = true;
  20.         BindingSource bsource = new BindingSource();
  21.         bsource.DataSource = ds;
  22.         dg.DataSource = bsource;
  23.         dg.Columns[0].Visible = false;
  24.         dg.Columns[1].Visible = false;
  25.         dg.Columns[2].HeaderText = "Fname";
  26.         dg.Columns[2].Width = 45;
  27.         dg.Columns[3].HeaderText = "Lname";
  28.         dg.Columns[3].Width = 45;
  29.         dg.Columns[5].HeaderText = "Gender";
  30.         dg.Columns[5].Width = 46;
  31.         dg.Columns[6].HeaderText = "Address";
  32.         dg.Columns[6].Width = 48;
  33.         dg.Columns[4].Visible = false;
  34.         dg.Columns[7].HeaderText = "Phone";
  35.         dg.Columns[7].Width = 45;
  36.         dg.Columns[8].HeaderText = "Mobile";
  37.         dg.Columns[8].Width = 45;
  38.         dg.Columns[9].HeaderText = "Email";
  39.         dg.Columns[9].Width = 45;
  40.         dg.Columns[10].HeaderText = "Project_ID";
  41.         dg.Columns[10].Width = 55;
  42.         dg.Columns[11].HeaderText = "Visit Date";
  43.         dg.Columns[11].Width = 55;
  44.         dg.Columns[12].HeaderText = "Agent";
  45.         dg.Columns[12].Width = 45;
  46.         dg.Columns[13].HeaderText = "FeedBack";
  47.         dg.Columns[14].HeaderText = "Remarks";
  48.         string feedback = "FeedBack";
  49.         dg.Columns[13].HeaderText = feedback;
  50.  
  51.         return ds;
  52.  
  53.    }
  54.  
  55.  
  56.   public int update()
  57.    {
  58.       OleDbConnection con = new OleDbConnection(@"provider= Microsoft.Jet.OLEDb.4.0; Data Source = D:\My Documents\Visual Studio 2005\Projects\db2.mdb");
  59.       con.Open();
  60.  
  61.      string sqlUpdate;
  62.       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'";
  63.       OleDbParameter[] pUpdate = new OleDbParameter[15];
  64.  
  65.  
  66.       pUpdate[0] = new OleDbParameter("@p1", OleDbType.VarChar, 40,"client_id");
  67.       pUpdate[1] = new OleDbParameter("@p2", OleDbType.DBDate, 30, "date");
  68.       pUpdate[2] = new OleDbParameter("@p3", OleDbType.VarChar, 40,"fname");
  69.       pUpdate[3] = new OleDbParameter("@p4", OleDbType.VarChar, 20,"lname");
  70.       pUpdate[4] = new OleDbParameter("@p5", OleDbType.VarChar, 20,"mname");
  71.       pUpdate[5] = new OleDbParameter("@p6", OleDbType.VarChar, 40, "gender");
  72.       pUpdate[6] = new OleDbParameter("@p7", OleDbType.VarChar, 40, "address");
  73.       pUpdate[7] = new OleDbParameter("@p8", OleDbType.Numeric, 9, "phone");
  74.       pUpdate[8] = new OleDbParameter("@p9", OleDbType.Numeric, 9, "mobile");
  75.       pUpdate[9] = new OleDbParameter("@p10", OleDbType.VarChar, 40, "email");
  76.       pUpdate[10] = new OleDbParameter("@p11", OleDbType.VarChar, 40, "project_id");
  77.       pUpdate[11] = new OleDbParameter("@p12", OleDbType.Date, 40, "visit_date");
  78.       pUpdate[12] = new OleDbParameter("@p13", OleDbType.VarChar, 40, "agent");
  79.       pUpdate[13] = new OleDbParameter("@p14", OleDbType.VarChar, 40, "feedback1");
  80.       pUpdate[14] = new OleDbParameter("@p15", OleDbType.VarChar, 30, "remarks");
  81.  
  82.       OleDbCommand cmdUpdate = new OleDbCommand(sqlUpdate,con);
  83.      // cmdUpdate.Parameters.AddRange(pUpdate);
  84.  
  85.  
  86.       OleDbDataAdapter da = new OleDbDataAdapter();
  87.       da.UpdateCommand  = cmdUpdate;
  88.       int i=da.Update(ds);
  89.       ds.AcceptChanges();
  90.        if(i>0)
  91.        {
  92.        MessageBox.Show("database updated");
  93.      }
  94.      return i;
  95.     }
  96.  
  97.  
  98.  }
thanks in advance
Radhika
Feb 24 '08 #1
1 1721
kenobewan
4,871 Expert 4TB
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?
Feb 24 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
3
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...
3
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== ...
5
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,...
11
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....
5
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
0
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...
3
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::...
9
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,...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.