473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VB.NET: Sql Syntax

I'm using VB.net and trying to do relatively simple SQL commands to an MS SQL server but am not having any luck. Can anybody give me some sample code with the correct syntax thanks
Nov 1 '06 #1
3 2280
sashi
1,754 Expert 1GB
Hi there,

Syntax for what? Update? Select? Insert? Delete? which one? As mentioned earlier, please try to be clearer when asking question.
Nov 1 '06 #2
Hi there,

Syntax for what? Update? Select? Insert? Delete? which one? As mentioned earlier, please try to be clearer when asking question.

sorry, if you have it for insert and select I'll try to work the rest.
Nov 1 '06 #3
willakawill
1,646 1GB
sorry, if you have it for insert and select I'll try to work the rest.
There are a couple of different elements that you have to control with SQL Server
1. VB syntax with ado
2. SQL Server security
3. SQL syntax

Here is something that covers all 3:
Expand|Select|Wrap|Line Numbers
  1. 'we need to declare the ado objects
  2. 'do not declare them using the New keyword
  3. 'this degrades performance
  4. Dim cnCon As ADODB.Connection
  5. Dim cmdCom AS ADODB.Command
  6. Dim rs As ADODB.Recordset
  7. Dim strSQL As String
  8.  
  9. 'open a connection to the database
  10.    Set cnCon = New ADODB.Connection
  11.     With cnCon
  12.         .Provider = "SQLOLEDB"
  13.         .Properties("Data Source") = "SQL server name here"
  14.         .Properties("User Id") = "your username here"
  15.         .Properties("Password") = "your password here"
  16.         .Open
  17.         .DefaultDatabase = "your database name here"
  18.      End With
  19.  
  20.      'set up the properties of the command object
  21.      Set cmdCom = New ADODB.Command
  22.      With cmdCom
  23.         .ActiveConnection = cnCon
  24.         .CommandType = adCmdText
  25.      End With
  26.  
  27.      'you have to decide what properties you want for your recordset
  28.      Set rs = New ADODB.Recordset
  29.      With rs
  30.         .ActiveConnection = cnCon
  31.         .CursorType = adOpenStatic
  32.         .CursorLocation = adUseClient
  33.         .LockType = adLockBatchOptimistic
  34.      End With
  35.  
  36.     strSQL = "SELECT blah1, blah2, blah3 " _
  37.             & "FROM MyTable " _
  38.             & "WHERE blah4 > blah5 " _
  39.             & "ORDER BY blah1"
  40.  
  41.      rs.Source = strSQL
  42.      rs.Open
  43.  
  44.      strSQL = "UPDATE MyTable " _
  45.             & "SET blah1 = 8 " _
  46.             & "WHERE blah4 > blah5 " 
  47.  
  48.      'an update statement does not return a recordset
  49.      'so we can use the command object
  50.      cmdCom.CommandText = strSQL
  51.      cmdCom.Execute
  52.  
I hope this is useful for you
Nov 1 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
37
by: Eric | last post by:
There is a VB.NET critique on the following page: http://www.vb7-critique.741.com/ for those who are interested. Feel free to take a look and share your thoughts. Cheers, Eric. Ps: for those...
72
by: Robin Tucker | last post by:
I need to find some documents/research for my manager about VB.NET v C# use. I've noticed that there are many more people using C# than VB.NET, that there seem to be more job vacancies specifying...
2
by: Qiao Yun | last post by:
I used vc++.net (visual studio .net ) to open a project which can work well in vc++6.0. I succeeded in compiling the project in vc++.net in release mode . But when I tried to compile the project...
132
by: Kevin Spencer | last post by:
About 2 years ago, and as recently as perhaps 1 year ago, I can recall seeing many posts about what language to use with ASP.Net. The consensus was that employers paid more for C# programmers, and...
47
by: rawCoder | last post by:
Hi, Just wanted to know if there is any speed difference between VB conversion Keywords like CInt, Clng, CStr, CDbl, CBool etc. ..NETs Convert.To<...> methods. And which is better to be...
1
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at...
1
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
4
by: Mike | last post by:
Hello everyone! I've been programming for several years doing web sites, web services, controls, etc. using VB6, VB.NET, C#, ASP, JavaScript and XML, well I'm bored with creating web sites and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.