regarding errors in database code
Hi Friends..
I am working on the Student Database project.I use the Visual Studio 2005.But it shows the error in the following code.I can try many times to tackle the problem but it get failed.
Following is the code which shows the errors.
PublicClass Form1
Dim objConn As SqlConnection = New SqlConnection("server=(local);database=studentdb;user id=Admin;password=;")
Dim ObjDataAdapter AsNew SqlDataAdapter()
Dim ObjDataSet AsNew DataSet()
Dim ObjDataView As DataView
Dim objCurrencyManager As CurrencyManager
also i added here code for Insert button to add the content to the Database.
PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim pos AsInteger, max AsInteger
Dim strid AsString
Dim objCommand As SqlCommand = New SqlCommand()
pos = objCurrencyManager.Position
Dim maxIdCommand As SqlCommand = New SqlCommand("SELECT MAX(name_id) As max" & "FROM student1 WHERE name_id LIKE 'DM%'", objConn)
objConn.Open()
Dim maxID AsObject = maxIdCommand.ExecuteScalar()
If maxID Is DBNull.Value Then
max = 1000
Else
strid = CType(maxID, String)
max = CType(strid.Remove(0, 2), Integer)
max += 1
EndIf
strid = "DM" & max.ToString
objCommand.Connection = objConn
objCommand.CommandText = "INERT INTO Student1(name,class,branch)" & "VALUES(@name,@class,@branch)"
objCommand.Parameters.Add("@name", TextBox1.Text)
objCommand.Parameters.Add("@class", TextBox2.Text)
objCommand.Parameters.Add("@branch", TextBox3.Text)
Try
objCommand.ExecuteNonQuery()
Catch SqlExceptionErr As SqlException
MessageBox.Show(SqlExceptionErr.Message)
EndTry
EndSub
error shown: type SqlConnection is not defined..
As i am new user of Visual Studio 2005,i don't get anything regarding the errors of the code.So please tell me detail steps of making Database connection.in VS 2005..
|