dbTalk Databases Forums  

Saving data to SQL Data Base

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Saving data to SQL Data Base in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Omar Abid
 
Posts: n/a

Default Saving data to SQL Data Base - 08-10-2007 , 07:07 AM






Hi,
I'm using the following code to open a data base and show it's content
in a Data Grid View
----
Code
-----
Imports System.Data.SqlClient

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As New SqlConnection("Data
Source=./wideserver;Path="c:/cct.mdf";User
Id=username;Password=Password;")
Using (conn)
conn.Open()
Dim com As SqlCommand = conn.CreateCommand()
Using (com)
com.CommandType = CommandType.Text

com.CommandText = "Select * From users"
Dim da As New SqlDataAdapter(com)
Using (da)
Dim dt As New DataTable("usertable")
Using (dt)
da.Fill(dt)
Dim dgv As New DataGridView()
dgv.Dock = DockStyle.Fill
dgv.DataSource = dt
Me.Controls.Add(dgv)
End Using
End Using
End Using
End Using
End Sub
-----
end code
-----

The following code allow me to see the table data in a Data Grid View
but now i want to save the changes in the table (after making
modifications in the dgv)
i use : dta.update(dt)
but that don't work !!!!!!
Any Help and thanks a lot
Omar Abid
www.omarabid.uni.cc


Reply With Quote
  #2  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Saving data to SQL Data Base - 08-10-2007 , 07:36 AM






Quote:
but now i want to save the changes in the table (after making
modifications in the dgv)
i use : dta.update(dt)
but that don't work !!!!!!
You need to set the SqlDataAdapter.UpdateCommand property. The UPDATE
command (as well as INSERT and DELETE) can be auto-generated if primary key
information can be derived from the SelectCommand and you use a
SqlCommandBuilder. See the VS documentation for details and examples.

Also, I suggest you consider using stored procedures for data access and
modification. Procs are more secure and promote execution plan re-use.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Omar Abid" <omar.abid2006 (AT) gmail (DOT) com> wrote

Quote:
Hi,
I'm using the following code to open a data base and show it's content
in a Data Grid View
----
Code
-----
Imports System.Data.SqlClient

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As New SqlConnection("Data
Source=./wideserver;Path="c:/cct.mdf";User
Id=username;Password=Password;")
Using (conn)
conn.Open()
Dim com As SqlCommand = conn.CreateCommand()
Using (com)
com.CommandType = CommandType.Text

com.CommandText = "Select * From users"
Dim da As New SqlDataAdapter(com)
Using (da)
Dim dt As New DataTable("usertable")
Using (dt)
da.Fill(dt)
Dim dgv As New DataGridView()
dgv.Dock = DockStyle.Fill
dgv.DataSource = dt
Me.Controls.Add(dgv)
End Using
End Using
End Using
End Using
End Sub
-----
end code
-----

The following code allow me to see the table data in a Data Grid View
but now i want to save the changes in the table (after making
modifications in the dgv)
i use : dta.update(dt)
but that don't work !!!!!!
Any Help and thanks a lot
Omar Abid
www.omarabid.uni.cc



Reply With Quote
  #3  
Old   
Omar Abid
 
Posts: n/a

Default Re: Saving data to SQL Data Base - 08-12-2007 , 05:34 AM



On Aug 10, 5:36 am, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.net> wrote:
Quote:
but now i want to save the changes in the table (after making
modifications in the dgv)
i use : dta.update(dt)
but that don't work !!!!!!

You need to set the SqlDataAdapter.UpdateCommand property. The UPDATE
command (as well as INSERT and DELETE) can be auto-generated if primary key
information can be derived from the SelectCommand and you use a
SqlCommandBuilder. See the VS documentation for details and examples.

Also, I suggest you consider using stored procedures for data access and
modification. Procs are more secure and promote execution plan re-use.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Omar Abid" <omar.abid2... (AT) gmail (DOT) com> wrote in message

news:1186747639.036460.260430 (AT) m37g2000prh (DOT) googlegroups.com...

Hi,
I'm using the following code to open a data base and show it's content
in a Data Grid View
----
Code
-----
Imports System.Data.SqlClient

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As New SqlConnection("Data
Source=./wideserver;Path="c:/cct.mdf";User
Id=username;Password=Password;")
Using (conn)
conn.Open()
Dim com As SqlCommand = conn.CreateCommand()
Using (com)
com.CommandType = CommandType.Text

com.CommandText = "Select * From users"
Dim da As New SqlDataAdapter(com)
Using (da)
Dim dt As New DataTable("usertable")
Using (dt)
da.Fill(dt)
Dim dgv As New DataGridView()
dgv.Dock = DockStyle.Fill
dgv.DataSource = dt
Me.Controls.Add(dgv)
End Using
End Using
End Using
End Using
End Sub
-----
end code
-----

The following code allow me to see the table data in a Data Grid View
but now i want to save the changes in the table (after making
modifications in the dgv)
i use : dta.update(dt)
but that don't work !!!!!!
Any Help and thanks a lot
Omar Abid
www.omarabid.uni.cc
Hi,
Thanks I know that i must use an Update command.
But i'm programming in compiling time, i can't use the VS data base
tool to generate update command
Omar Abid
www.omarabid.uni.cc



Reply With Quote
  #4  
Old   
Dan Guzman
 
Posts: n/a

Default Re: Saving data to SQL Data Base - 08-13-2007 , 06:38 AM



Quote:
Thanks I know that i must use an Update command.
But i'm programming in compiling time, i can't use the VS data base
tool to generate update command
You can create your own UpdateCommand manually. Be sure to specify all
columns that were returned by the SelectCommand.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Omar Abid" <omar.abid2006 (AT) gmail (DOT) com> wrote

Quote:
On Aug 10, 5:36 am, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.net> wrote:
but now i want to save the changes in the table (after making
modifications in the dgv)
i use : dta.update(dt)
but that don't work !!!!!!

You need to set the SqlDataAdapter.UpdateCommand property. The UPDATE
command (as well as INSERT and DELETE) can be auto-generated if primary
key
information can be derived from the SelectCommand and you use a
SqlCommandBuilder. See the VS documentation for details and examples.

Also, I suggest you consider using stored procedures for data access and
modification. Procs are more secure and promote execution plan re-use.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Omar Abid" <omar.abid2... (AT) gmail (DOT) com> wrote in message

news:1186747639.036460.260430 (AT) m37g2000prh (DOT) googlegroups.com...

Hi,
I'm using the following code to open a data base and show it's content
in a Data Grid View
----
Code
-----
Imports System.Data.SqlClient

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As New SqlConnection("Data
Source=./wideserver;Path="c:/cct.mdf";User
Id=username;Password=Password;")
Using (conn)
conn.Open()
Dim com As SqlCommand = conn.CreateCommand()
Using (com)
com.CommandType = CommandType.Text

com.CommandText = "Select * From users"
Dim da As New SqlDataAdapter(com)
Using (da)
Dim dt As New DataTable("usertable")
Using (dt)
da.Fill(dt)
Dim dgv As New DataGridView()
dgv.Dock = DockStyle.Fill
dgv.DataSource = dt
Me.Controls.Add(dgv)
End Using
End Using
End Using
End Using
End Sub
-----
end code
-----

The following code allow me to see the table data in a Data Grid View
but now i want to save the changes in the table (after making
modifications in the dgv)
i use : dta.update(dt)
but that don't work !!!!!!
Any Help and thanks a lot
Omar Abid
www.omarabid.uni.cc

Hi,
Thanks I know that i must use an Update command.
But i'm programming in compiling time, i can't use the VS data base
tool to generate update command
Omar Abid
www.omarabid.uni.cc



Reply With Quote
  #5  
Old   
Omar Abid
 
Posts: n/a

Default Re: Saving data to SQL Data Base - 08-14-2007 , 06:35 AM



On Aug 13, 4:38 am, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.net> wrote:
Quote:
Thanks I know that i must use an Update command.
But i'm programming in compiling time, i can't use the VS data base
tool to generate update command

You can create your own UpdateCommand manually. Be sure to specify all
columns that were returned by the SelectCommand.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Omar Abid" <omar.abid2... (AT) gmail (DOT) com> wrote in message

news:1186914886.560453.106490 (AT) r34g2000hsd (DOT) googlegroups.com...

On Aug 10, 5:36 am, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.net> wrote:
but now i want to save the changes in the table (after making
modifications in the dgv)
i use : dta.update(dt)
but that don't work !!!!!!

You need to set the SqlDataAdapter.UpdateCommand property. The UPDATE
command (as well as INSERT and DELETE) can be auto-generated if primary
key
information can be derived from the SelectCommand and you use a
SqlCommandBuilder. See the VS documentation for details and examples.

Also, I suggest you consider using stored procedures for data access and
modification. Procs are more secure and promote execution plan re-use.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Omar Abid" <omar.abid2... (AT) gmail (DOT) com> wrote in message

news:1186747639.036460.260430 (AT) m37g2000prh (DOT) googlegroups.com...

Hi,
I'm using the following code to open a data base and show it's content
in a Data Grid View
----
Code
-----
Imports System.Data.SqlClient

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As New SqlConnection("Data
Source=./wideserver;Path="c:/cct.mdf";User
Id=username;Password=Password;")
Using (conn)
conn.Open()
Dim com As SqlCommand = conn.CreateCommand()
Using (com)
com.CommandType = CommandType.Text

com.CommandText = "Select * From users"
Dim da As New SqlDataAdapter(com)
Using (da)
Dim dt As New DataTable("usertable")
Using (dt)
da.Fill(dt)
Dim dgv As New DataGridView()
dgv.Dock = DockStyle.Fill
dgv.DataSource = dt
Me.Controls.Add(dgv)
End Using
End Using
End Using
End Using
End Sub
-----
end code
-----

The following code allow me to see the table data in a Data Grid View
but now i want to save the changes in the table (after making
modifications in the dgv)
i use : dta.update(dt)
but that don't work !!!!!!
Any Help and thanks a lot
Omar Abid
www.omarabid.uni.cc

Hi,
Thanks I know that i must use an Update command.
But i'm programming in compiling time, i can't use the VS data base
tool to generate update command
Omar Abid
www.omarabid.uni.cc
Hi,
Thanks for your reply. I'm new to SQL and just learning. Do you direct
links (that contain specific thing that i need)
If so post those links
Thanks for understanding
Omar Abid
www.omarabid.uni.cc



Reply With Quote
  #6  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Saving data to SQL Data Base - 08-14-2007 , 04:29 PM



Omar Abid (omar.abid2006 (AT) gmail (DOT) com) writes:
Quote:
Thanks for your reply. I'm new to SQL and just learning. Do you direct
links (that contain specific thing that i need)
If so post those links
If you are to work with ADO .Net, you need to learn to with MSDN Library,
either on disk or on the web.

The link for the .UpdateCommand property in MSDN Library is
ms-
help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref10/html/P_Syste
m_Data_SqlClient_SqlDataAdapter_UpdateCommand.htm

If you are new to ADO .Net in general and want a head start, I recommend
David Sceppa's "ADO .Net Core Reference".


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #7  
Old   
Omar Abid
 
Posts: n/a

Default Re: Saving data to SQL Data Base - 08-17-2007 , 10:27 AM



On Aug 14, 2:29 pm, Erland Sommarskog <esq... (AT) sommarskog (DOT) se> wrote:
Quote:
Omar Abid (omar.abid2... (AT) gmail (DOT) com) writes:
Thanks for your reply. I'm new to SQL and just learning. Do you direct
links (that contain specific thing that i need)
If so post those links

If you are to work with ADO .Net, you need to learn to with MSDN Library,
either on disk or on the web.

The link for the .UpdateCommand property in MSDN Library is
ms-
help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref10/html/P_Syste
m_Data_SqlClient_SqlDataAdapter_UpdateCommand.htm

If you are new to ADO .Net in general and want a head start, I recommend
David Sceppa's "ADO .Net Core Reference".

--
Erland Sommarskog, SQL Server MVP, esq... (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Hi Erland Sommarskog,
I see thanks very much for your interest
Omar Abid
www.omarabid.uni.cc



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.