Friday, March 23, 2012

Saving data to SQL Data Base

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.ccOmar Abid (omar.abid2006@.gmail.com) writes:

Quote:

Originally Posted by

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@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||On Aug 14, 2:29 pm, Erland Sommarskog <esq...@.sommarskog.sewrote:

Quote:

Originally Posted by

Omar Abid (omar.abid2...@.gmail.com) writes:

Quote:

Originally Posted by

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...@.sommarskog.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

No comments:

Post a Comment