| | |
Show Data in DataGrid with VB.Net 2003 and SQLServer 2000
Please support our VB.NET advertiser: Intel Parallel Studio Home
This Code is easy way to load / show data in Datagrid. This Code write in vb.net 2003 and use sqlserver 2000 as database. I use module to connected VB.Net with SqlServer 2000. so the function to connected can be use in every form in this project.
'This Code needed one DataGrid On Form. 'In Module 'Declare outside of class Imports System.Data Imports System.Data.SqlClient Module Koneksi Public conn As SqlConnection Public Function GetConnect() conn = New SqlConnection("server = MyServerName;database = MyDatabaseName;Trusted_Connection = yes") Return conn End Function End Module 'In Form 'Declare outside of class Imports System.Data Imports System.Data.SqlClient 'Procedure To show data in DataGrid Private Sub ShowDataGrid() Dim conn As SqlConnection Dim cmdStudent As New SqlCommand Dim daStudent As New SqlDataAdapter Dim dsStudent As New DataSet Dim dtStudent As New DataTable conn = GetConnect() Try cmdStudent = conn.CreateCommand cmdStudent.CommandText = "SELECT * FROM YourTableName" daStudent.SelectCommand = cmdStudent daStudent.Fill(dsStudent, "YourTableName") dgStudent.DataSource = dsStudent dgStudent.DataMember = "YourTableName" dgStudent.ReadOnly = True Catch ex As Exception MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!") End Try End Sub ' Call procedure ShowDataGrid() on event Form Load Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ShowDataGrid() ' Load data to view in data grid End Sub ' You can change the event to call this procedure like in button pressed and etc..
0
•
•
•
•
hi I'm doing a similar project where I use a VB system to create users for the SQL server.
I created a dataset (I'm assuming this is the same as creating a module?) and I have a text box called txtUsername and one called txtPassword and a command button called cmdCreate
Obviously the user would fill in the text boxes with information on the new user and when they click the command button it will create a new user with those details. Could you possibly modify the above code to do this and perhaps show error messages in the VB display for instance if a user already exists etc etc.
Thanks for your help
Chris
I created a dataset (I'm assuming this is the same as creating a module?) and I have a text box called txtUsername and one called txtPassword and a command button called cmdCreate
Obviously the user would fill in the text boxes with information on the new user and when they click the command button it will create a new user with those details. Could you possibly modify the above code to do this and perhaps show error messages in the VB display for instance if a user already exists etc etc.
Thanks for your help
Chris
0
•
•
•
•
I received an error when running this :
Error: .NET SqlClient Data Provider: SQL Server does not exist or access denied.
This is what I have for the GetConnect funtion:
Public Function GetConnect()
Dim ServerName As String = "SA1SQL19"
Dim DatabaseName As String = "APPRAISAL"
conn = New SqlConnection("server = ServerName;database = DatabaseName;Trusted_Connection = yes")
Return conn
End Function
Please help! Thank you!
Error: .NET SqlClient Data Provider: SQL Server does not exist or access denied.
This is what I have for the GetConnect funtion:
Public Function GetConnect()
Dim ServerName As String = "SA1SQL19"
Dim DatabaseName As String = "APPRAISAL"
conn = New SqlConnection("server = ServerName;database = DatabaseName;Trusted_Connection = yes")
Return conn
End Function
Please help! Thank you!
0
•
•
•
•
Public Function GetConnect()
Dim ServerName As String = "SA1SQL19"
Dim DatabaseName As String = "APPRAISAL"
conn = New SqlConnection("server = ServerName;database = DatabaseName;Trusted_Connection = yes")
Return conn
End Function
try this :
Dim ServerName As String = "SA1SQL19"
Dim DatabaseName As String = "APPRAISAL"
conn = New SqlConnection("server = ServerName;database = DatabaseName;Trusted_Connection = yes")
Return conn
End Function
try this :
vb Syntax (Toggle Plain Text)
Public Function GetConnect() conn = New SqlConnection("server = SA1SQL19;database = APPRAISAL;Trusted_Connection = yes") Return conn End Function
0
•
•
•
•
hi im a newbie here, and i tried your code above but it seems there's an error appear..
here is my code for the connection in sql server..
<conn = New SqlConnection("server =(local);database = HR;Trusted_Connection = yes>
Error: .net SQLclient data provider: Line1: incorrect syntax near '202'.
pls help me pls..tnx
here is my code for the connection in sql server..
<conn = New SqlConnection("server =(local);database = HR;Trusted_Connection = yes>
Error: .net SQLclient data provider: Line1: incorrect syntax near '202'.
pls help me pls..tnx
Similar Threads
- Fill DataGrid with SqlServer Table (VB.NET)
- vb.net 2003 insert retrieve image in sql 2000 (VB.NET)
- ms sqlserver 2000 help (MS SQL)
- current data show in datagrid (Visual Basic 4 / 5 / 6)
- Delete a row in a datagrid and the underlying database vb net 2003 (VB.NET)
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google gridview hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year



