473,770 Members | 4,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

7 New Member
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_gro d 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 1765
kenobewan
4,871 Recognized Expert Specialist
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
1737
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 difficult to find it in the jungle of MSDN. thanks! Eric
3
4271
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 several examples on the web. They all seem to have problems, though that I've been unable to resolve. The most promising example I have found is at:
3
10413
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== using System; using System.Drawing; using System.Collections; using System.ComponentModel;
5
2377
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, check boxes, date pickers, combo boxes and datagrids). I have been coding alone on this project for about a year, and I have experienced many problems which have not been addressed by various SP's, including the recent SP1 to Framework.NET 1.1,...
11
2055
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. Hopefully someone here can help. I am just learning VB.NET and purchased the SAM's "Teach Yourself VB.NET 2003 in 21 days' book. I am trying to connect to an Access database I created locally on my computer per Chapter 16. I originally had it on a...
5
2599
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
3626
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 appreaciated. Thanks. Code below: Imports System.Data.OleDb Public Class Form2 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code "
3
1460
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:: ---------------------- c:\inetpub\wwwroot\sampleprj1\WebForm1.aspx.vb(151): 'Textbox' is ambiguous, imported from the namespaces or types 'System.Web.UI.WebControls, System.Windows.Forms'. ------------------------------ The code is as...
9
2673
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, should I use ViewState to store and reload the data, or should I load the data from the database on each postback? Assume for the sake of this question that I only care about performance, I don't care about ease of programming.
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.