how to connect VB to SQl Server 2000
|
|||
|
Rank: Unregistered
|
hi..would like to know how to connect vb6 to sql server..when connect to Microsoft access, i used the following code but what about in SQl server 2000? any good website to recommend?thanks.
Dim cn As New ADODB.Connection Dim provStr As String cn.Provider = "sqloledb" provStr = "Server=(local);Database=test2;Trusted_Connection=yes" cn.Open provStr Private Sub Command1_Click() Dim strsql As String <--how to do it in Sql Server 2000?? strsql = "select * from patient " mrscust.Source = strsql Set mrscust.ActiveConnection = cn mrscust.Open mrscust.AddNew mrscust.Fields("PatientID" mrscust.Fields("PatientName" mrscust.Update mrscust.Close End Sub |
||
|
|||
|
|||
|
Rank: ? (4821)
Member #: 3416 |
i would expect that the only difference would be in the provStr, but i'm not sure what you need to change it to.
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: Unregistered
|
Set cnn = New ADODB.Connection
' Open a connection by referencing the ODBC driver. cnn.ConnectionString = "driver={SQL Server};" & _ "server=???;uid=;pwd=;database=???" cnn.Open |
||
|
|||
|
|||
|
Rank: Unregistered
|
how to connect VB.net to SQl Server 2000
|
||
|
|||
|
|||
|
Rank: Unregistered
|
this is the way how i conected my vb with oracle..
Global OraSession As Object Global OraDatabaseOthers As Object Sub Main() Set OraSession = CreateObject("OracleInProcServer.XOraSession" Set OraDatabaseOthers = OraSession.OpenDatabase("tv3prod", "cma/crm", 0& End Sub so, how can i modify this codes so that i can connect it to sql server? |
||
|
|||
|
This post has been removed by a moderator (reason: smiley spam)
|
|||
|
|||
|
This post has been removed by a moderator (reason: smiley spam)
|
|||
|
|||
|
|||
|
Rank: Unregistered
|
have this
|
||
|
|||
|
|||
|
Rank: Unregistered
|
Code for Connect and Execute Buttons
'********* Connect Command Button Code ************** Private Sub cmdConnect_Click() On Error Resume Next ' Validate user supplied login arguments ' ... validation code goes here 'Create connect string from user input box values strConnect = "Provider=SQLOLEDB.1" _ & ";User ID=" & Me!txtUID _ & ";Password=" & Me!txtPWD _ & ";Initial Catalog=" & Me!txtDatabase _ & ";Data Source=" & Me!txtServer Screen.MousePointer = vbHourglass 'Call sub to test connect string If TestConnectString(strConnect) = False Then strMsg = "Server not found or login invalid." MsgBox strMsg, vbExclamation, "Error" 'Exit the routine because there was an error Else 'Toggle command buttons and text boxes appropriately '... do stuff here End If Screen.MousePointer = vbNormal End Sub '********* Test Connect String Sub ************** Function TestConnectString(ByVal sConn As String) As Boolean On Error Resume Next Dim cnn As ADODB.Connection Set cnn = New ADODB.Connection 'TestConnectString initializes to False by default cnn.Open sConn 'No error means that the connect string works! If Err.Number = 0 Then TestConnectString = True ' Clean up and release resources cnn.Close Set cnn = Nothing End Function '********* Execute Command Button Code ************** Private Sub cmdExecute_Click() On Error Resume Next Dim cnn As ADODB.Connection Dim rst As ADODB.Recordset Dim fld As ADODB.Field Dim strMsg As String Dim strHeaders As String Dim strResults As String ' Simple validation that SQL statement exists If Len(Me!txtSQL) = 0 Then strMsg = "Enter a valid SQL Statement." MsgBox strMsg, vbExclamation, "Error" Exit Sub End If MousePointer = vbHourglass ' Instantiate Connection and Recordset objects Set cnn = New ADODB.Connection Set rst = New ADODB.Recordset ' Open Connection and Load Recordset cnn.Open strConnect rst.Open CStr(Me!txtSQL), cnn ' Create column headers For Each fld In rst.Fields strHeaders = strHeaders & UCase(fld.Name) & vbTab Next ' Use the GetString method to retrieve recordset text strResults = rst.GetString(adClipString, -1, vbTab, vbCrLf) ' Return header and data to results pane Me!txtResults = strHeaders & vbCrLf & strResults ' If there was an error then replace the output ' text with the description of the error. If Err.Number > 0 Then Me!txtResults = Err.Description ' Clean up and release resources rst.Close Set rst = Nothing cnn.Close Set cnn = Nothing MousePointer = vbNormal End Sub |
||
|
|||
|
|||
|
Rank: Unregistered
|
Please provide me basic about connect vb.net to sql server 2000. how many way connect to sql server 2000 by use vb.net. how can I do if I want to print any table on sql server 2000 by write code.
My e-mail is : nolvanroth@yahoo.com Best Regards, Nol vanroth. |
||
|
|||
|
This post has been removed by a moderator (reason: double post)
|
|||
|
|||
|
|||
|
Rank: Unregistered
|
Please provide me basic about connect vb and vb.net to sql server. how many way connect to sql server by use vb.net. how can I do if I want to print any table on sql server by write code.And what is diffe. in ADO and ADO.net
My e-mail is : shekh_mohasin@yahoo.om Best Regards, Shekh |
||
|
|||
|
|||
|
Rank: Unregistered
|
I have one method to connect VB to SQL 2000
Those are: Step 1: You have to create one folder to store all of your files. Step 2: You must save one notepad file into your created folder before and change its extension from " .txt " --> " .udl " Step 3: Choose your Database name in your SQL 2000 and Click on Test Connection Button. If your testing is successfull please close it. Step 4: In VB: Dim cn as ADODB.connection Dim rs as New ADODB.recordset ---------------- set cn=new ADODB.connect cn.open "file name=' " & app.path & "\file.udl" rs.open "TableName",cn ---------------- ----------------- ----------------- |
||
|
|||
|
|||
|
Rank: Unregistered
|
How to execute .sql file in Visual basic 6.0
|
||
|
|||
|
|||
|
Rank: Unregistered
|
what i do with VB and sql server
|
||
|
|||
|
|||
|
Rank: Unregistered
|
reenakaundal@yahoo.co.in
|
||
|
|||
|
This post has been removed by a moderator (reason: smiley spam)
|
|||
|
|||
|
|||
|
Rank: Unregistered
|
|
||
|
|||
|
|||
|
Rank: Unregistered
|
result connect all test:
cnn.ConnectionString = "driver={SQL Server};" & _ "server=test;uid=;pwd=;database=test" |
||
|
|||
|
|||
|
Rank: Unregistered
|
In relation with "SQL SERVER" so how would you put those tables appear in databound grids?
|
||
|
Please login or register to post a reply.