473,384 Members | 1,854 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,384 software developers and data experts.

How to make the connection class to sql server 2000 from a vb.net form?

navanova
I have three questions.

1. I have created sql connection to sql server 2000 from a vb.net form. However, I just want to make the connection class and I also want to know how to call that connection class from different forms to connect to sql server 2000.

2. Can I use the query from this class? Because, this connection class will be used by a number of forms.

3. TextBox1.Text, TextBox2.Text, TextBox2.Text are also not recognized by this connection class.

The connection that I've created is as follows:

Expand|Select|Wrap|Line Numbers
  1. Public Class Connection
  2.  
  3.  
  4.  
  5.     Private Sub btnConnect_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
  6.  
  7.         Dim fir As String
  8.         Dim sec As String
  9.         Dim age As Integer
  10.  
  11.         fir = TextBox1.Text
  12.         sec = TextBox2.Text
  13.         age = TextBox3.Text
  14.  
  15.  
  16.         Dim strCNStr As String = "Data Source=ITSAD;Initial Catalog=Inspection;User ID=sa;Password=;"
  17.  
  18.  
  19.         Dim cnDB As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection
  20.  
  21.         Dim cmdDB As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("Insert into Branch(Fname,Lname,age) VALUES ('" & fir & "','" & sec & "','" & age & "')", cnDB)
  22.         Dim rdAuther As System.Data.SqlClient.SqlDataReader
  23.  
  24.         cnDB.ConnectionString = strCNStr
  25.         cnDB.Open()
  26.  
  27.  
  28.         rdAuther = cmdDB.ExecuteReader()
  29.  
  30.  
  31.         rdAuther.Close()
  32.  
  33.  
  34.         cnDB.Close()
  35.  
  36.  
  37.     End Sub
  38.  
  39. End Class

Thank you
Feb 22 '07 #1
2 2272
I have three questions.

1. I have created sql connection to sql server 2000 from a vb.net form. However, I just want to make the connection class and I also want to know how to call that connection class from different forms to connect to sql server 2000.

2. Can I use the query from this class? Because, this connection class will be used by a number of forms.

3. TextBox1.Text, TextBox2.Text, TextBox2.Text are also not recognized by this connection class.

The connection that I've created is as follows:

Expand|Select|Wrap|Line Numbers
  1. Public Class Connection
  2.  
  3.  
  4.  
  5.     Private Sub btnConnect_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
  6.  
  7.         Dim fir As String
  8.         Dim sec As String
  9.         Dim age As Integer
  10.  
  11.         fir = TextBox1.Text
  12.         sec = TextBox2.Text
  13.         age = TextBox3.Text
  14.  
  15.  
  16.         Dim strCNStr As String = "Data Source=ITSAD;Initial Catalog=Inspection;User ID=sa;Password=;"
  17.  
  18.  
  19.         Dim cnDB As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection
  20.  
  21.         Dim cmdDB As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("Insert into Branch(Fname,Lname,age) VALUES ('" & fir & "','" & sec & "','" & age & "')", cnDB)
  22.         Dim rdAuther As System.Data.SqlClient.SqlDataReader
  23.  
  24.         cnDB.ConnectionString = strCNStr
  25.         cnDB.Open()
  26.  
  27.  
  28.         rdAuther = cmdDB.ExecuteReader()
  29.  
  30.  
  31.         rdAuther.Close()
  32.  
  33.  
  34.         cnDB.Close()
  35.  
  36.  
  37.     End Sub
  38.  
  39. End Class

Thank you




Hi, your query is okey but try to make it OOP in order to use it in other forms and change Excutereader to ExcuteScaler, it's better to use providers
Feb 22 '07 #2
Hi, your query is okey but try to make it OOP in order to use it in other forms and change Excutereader to ExcuteScaler, it's better to use providers

Yes, I know I've to make it OOP in order to use it in other forms. But what is the procedure of making it accessable across other forms? what namespaces should be incorporated on other forms to access the connection class?

Thank you
Feb 23 '07 #3

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

Similar topics

0
by: Sham Yemul | last post by:
Hello, We developed an application that has many data entry forms and data controls in Vb.net and Sql Server2000 as backend. For this application we created connection object on load event of...
7
by: Keith Norris | last post by:
I cannot successfully create a connection object in a web form. In the page_load event I try the following code: Dim sConnection As String = "server=MIDATLANTICUS;" & _ database=Pubs;integrated...
26
by: Rajeev Tipnis | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en- us;819450 Questions: 1) Is this patch (fix) applicable to the .NET 1.1 Framework as well? That is, if we have Framework 1.1 (On...
17
by: Danieltbt05 | last post by:
just installed SQL server 2000 and using my client , i can't locate the server. I used SQL query analyzer to search but no servers were found. Error message is as below Server : Msg17,level...
1
by: Marc Eggenberger | last post by:
Hi there .. I have the following scenario. I have a Webservice which is running under Win2003/IIS6 with .Net1.1 The Service itselfs connects to a database which is a SQL 2000 on a Server in...
2
by: AS | last post by:
Hi, I have a C# windows desktop application that will be used only by one user at a time. The database server (SQL Server 2000) also resides on that machine only. This application has three...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
by: Horia Demian | last post by:
I have the following code in a web form which use a connection to SQL Server 2000. I use this form to display a list of products from a table. The connection string to the database server is stored...
3
by: fniles | last post by:
In the Windows application (using VB.NET 2005) I use connection pooling like the following: In the main form load I open a connection using a connection string that I stored in a global variable...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.