473,320 Members | 1,802 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,320 software developers and data experts.

C# Add/Update records from DataGridView to SQL database. ADO.NET

5
I have a table called Student in a SQL databse.. I have to create a simple windows application in C# to Retrieve that table for the following functions..
1.Add Data
2.Update Data
3.View Data

For this Im using Datagridview and ADO.NET.. Im able to view the data.. but I dont know how to Add and update data...
When I add/update the changes should be done in the SQL database.. How can I do that?
Any help?

This is the method Im using for View the data

Expand|Select|Wrap|Line Numbers
  1. public DataSet Retrieve()
  2.         {
  3.             SqlConnection conn = new
  4.                 SqlConnection("Server=White\\SQLEXPRESS;Integrated Security=SSPI;database=Student);
  5.             SqlDataAdapter cmd = new SqlDataAdapter("select * from students", conn);
  6.             DataSet result = new DataSet();
  7.             cmd.Fill(result, "students");
  8.             return result;
  9.         }
  10.  
  11.  
  12. private void Form1_Load(object sender, EventArgs e)
  13.         {
  14.             System.Data.DataSet DS = new System.Data.DataSet();
  15.             StuData.Class1 ostu = new StuData.Class1();
  16.             DS = ostu.Retrieve();
  17.             dataGridView1.DataSource = DS.Tables[0];
  18.         }
Feb 23 '08 #1
1 3461
kenobewan
4,871 Expert 4TB
Please search the site for examples. HTH.
Feb 24 '08 #2

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

Similar topics

1
by: Joaquin | last post by:
OK, I hate myself for asking this, it's the worst question I have ever asked but it's worse not to ask: ¿How do I update a datatable in vs 2005? I mean, I am using a typed dataset, a...
1
by: Dave | last post by:
I have a table with 3 fields of which the primary key is a autonumber. I have created my dataadapter, dataset and datagridview using a wizard. However, in the datagrid, the update and delete...
6
by: Greg P | last post by:
I am using VS2005 and have been learning a ton about databinding. I know that when you drag a view from the datasource window (creating a dataGridView) that an update method is not added to the...
0
by: Niyazi | last post by:
Hi, I have a form with DataGrid view and details and its working fine. In the sepaerate button I want to update the database table columns. The value comes from AS400 and inserted into string...
3
by: =?Utf-8?B?THVib21pcg==?= | last post by:
Hi, I have a DataGridView that displays data from one table from database. I didn’t implement any my code, I just used wizard to do all the work with DatagridView populating. Visual Studio...
13
by: Terry Olsen | last post by:
I'm using OleDb to connect with an Access Database. I have anywhere from 10 to over 100 records that I need to either INSERT if the PK doesn't exist or UPDATE if the PK does exist, all in a single...
0
by: sonia.sardana | last post by:
I m using ADODB+ SQL. Mine SQL table is create database student use student create table stu_table(roll int primary key,name varchar(10), marks int)
2
by: Oleg Subachev | last post by:
I have DataGridView which DataSource is assigned to Table<> object of DataContext connected to SQL Server database. But when the underlying SQL Server database is updated (through ODBC...
0
by: bharathi228 | last post by:
Hi, iam working with windows application.here my requirement is binding data to database from a datagridview. next i want to update some rows in datagridview and update it to the database.for...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.