I've been doing a self studies on visual basic and I thought I've learned a lot but still I realized that I still have
something more to learn. I want to learn the basic fundamentals on SQL for its database operations such as
adding,editing, and deleting records. I would say I'm new to SQL because as far as I've used VB, I've been using LINQ(Language Integrated Queries) for database operation. I've been doing a lot of research online on how to start and connect to SQL but I find hard to make it on my own cause all I've got is an error during runtime. I need an assistance on this matter. I just want a complete step by step process on how to connect and starts with the database operations such as add,edit, and delete. Informative links would also be very helful to me as well. All I need is the correct basic steps procedure on how to start with SQL 2005 so I can move on and walkthrough all the way about this topic which I already did when I started to study LINQ. Take note that I'm using Visual Basic 2008 Express Edition under Visual Studio 2008 and I believe that the MS SQL Server 2005 is pre-installed when you install the visual basic. Below is the code I tried to use from what I've got online and all I've got is an error.
****code*****
Imports System.Data.SqlClient 'code above the form load event
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myConnection As New SqlConnection
Dim myCommand As New SqlCommand
Dim ra As Integer
'the filename of my database is strongwind
myConnection = New SqlConnection("server=localhost;uid=sa;pwd=;database=strongwind.mdf")
myConnection.Open()
myCommand = myConnection.CreateCommand
'the name of my table is just Table1
myCommand.CommandText = "INSERT INTO Table1(ID Number, Name, Age, Status) VALUES('" & Trim(TextBox1.Text) & " ','" & Trim(TextBox2.Text) & "','" & Trim(TextBox3.Text) & "','" & Trim(TextBox4.Text) & "')"
ra = myCommand.ExecuteReader.RecordsAffected
MsgBox("New records are added.", MsgBoxStyle.Information)
myConnection.Close()
End Sub
****error*****
Sql Exception was unhandled: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I don't know if there's something wrong with the connection string or even the code itself. Please correct it.
Thanks for any help that will be contributed...tim mack
This post has been edited by modi123_1: 18 September 2011 - 09:12 AM
Reason for edit:: please use the code tags

New Topic/Question
Reply




MultiQuote





|