•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 363,778 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,473 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
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..
Comments (Newest First)
chrisdent1986 | Newbie Poster | May 29th, 2008
•
•
•
•
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
kimhanu | Newbie Poster | Mar 26th, 2008
•
•
•
•
very good
thanks you
thanks you
ITKnight | Light Poster | Feb 7th, 2008
•
•
•
•
worked nice
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)