Click to See Complete Forum and Search --> : DataGrid values inserted in SQL Server
isha_rastogi2006
April 10th, 2006, 03:45 AM
Hi,
I am working on Desktop Application using C#.Net. I have generate a runtime datagrid using datatable and create a column and rows.I will take input from the user in a DataGrid and I want to insert this datagrid values in SQL Server. Please anyone tell me its very urgent.
Thank You
DanielaTm
April 10th, 2006, 06:57 AM
If you are adding the run-time values into datatable and after that in datagrid, you have the values, so parse it and save it into database from here
jhammer
April 10th, 2006, 12:04 PM
You will need a DataAdapter and a DataConnection in order to store the data into the database. look for SqlDataAdapter.Update method.
aniskhan
April 10th, 2006, 05:52 PM
Declarations
public string dbQuery = "select * from student";
public string myConnectionString = ".....";
sqlConnection myConnection;
DataSet objDS;
sqlDataAdapter adapter;
load the datainto dataGrid
private void Form1_Load(...)
{
objDS= new DataSet();
myConnection= new sqlConnection(myConnectionString);
adapter= new sqlDataAdapter(dbQuery, myConnection);
try
{
myConnection.Open();
adapter.Fill(objDS);
this.dataGrid1.DataSource=objDS.Tables[0];
}
catch(SystemException ex)
{
MessageBox.Show(ex.Message);
}
}
save the changes in the datagrid
private void button1_Click(....)
{
if (objDS.HasChanges())
{
sqlCommandBuilder command_builder;
command_builder = new sqlCommandBuilder(adapter);
adapter.Update(objDS);
}
}
isha_rastogi2006
April 12th, 2006, 02:10 AM
Hi aniskhan,
I have seen your reply but plz tell me what is dbquery.please explain your query.
Thanks 4 reply,
vivekshah
April 12th, 2006, 02:55 AM
The dbquery you got from aniskhan is the simple database query , that has to be updated by u as per your requirment.
hope u may have got it.
good luck
isha_rastogi2006
April 12th, 2006, 03:27 AM
Hi aniskhan,
Thank you 4 reply. Its working properly.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.