Dim strConnection As String = “data source=(local);initial catalog=testDB; user id=sa; password=1234;”
Dim objConnection As New SqlConnection(strConnection)
Dim strSQL As String = “SELECT * from tblTest;”
Dim objCommand As New SqlCommand(strSQL, objConnection)
objConnection.Open()
Response.Write(“ServerVersion: ” & objConnection.ServerVersion & _
vbCrLf & “Datasource: ” & objConnection.DataSource & _
vbCrLf & “Database: ” & objConnection.Database)
DataGrid1.DataSource = objCommand.ExecuteReader()
DataGrid1.DataBind()
objConnection.Close()
Very nice code. I’ve been struggling to find code to connect to a SQL database for a week and came up with nothing. Everyone has posted complicated snippets which leave the novice lost. This was simple, and no doubt i will be able to build on it on my own.
Thanks again.
Thanks a lot.
Really feel happy if i can help anyone.
Thanks …
Very nice code.
hello,
I have 2 field name nodaftar n tahunkewangan in a table n I want to compare tahun kewangan where I want to display nodaftar which is tahunkewangan 2009 is not in the database…how can I do the comparison.
Hi Ashraf
could you please help me with the below quary;
Dim rdoEn As rdoEngine
Dim rdoEv As rdoEnvironment
Dim rdoCn As rdoConnection
Dim rdoRS As rdoResultset
Set rdoEn = rdoEngine
Set rdoEv = rdoEn.rdoEnvironments(0)
Set rdoCn = rdoEv.OpenConnection(“”, , , “DSN=datas;UID=MyUID;PWD=Password;”)
Set rdoRS = rdoCn.OpenResultset(“select no from deposit where code = ‘FD’ order by to_number(no) desc”)
If rdoRS.EOF = True Then
Text1.Text = 1
Else
Text1.Text = rdoRS(0) + 1
End If
rdoRS.Close
The Above was made in VB6 .. But Iam unable to do the same in VB2008 ..
Could you please tell me how i can be able to use the same type quary in my vb 2008.
I have a text box on my form that will display a last No on my database at the time of form load .
Thanks Alot
CAN U PLEASE POST A COMPLETE CODE…TNX..
ah mayat hapa agpaiso liyay ni kanyo…halamat ni ambanaw,,tapai
Hi Ashrafur
It’s the first VB code I deployed successfully by my own… nice code!
Can you give me some hint as well how to Edit, Update and Insert data into a GridView?
Thanks,
David