Wrox Programmer Forums
|
Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2010, 09:09 PM
Authorized User
 
Join Date: Mar 2009
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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..





Similar Threads
Thread Thread Starter Forum Replies Last Post
regarding errors in database code UmeshA SQL Language 1 February 22nd, 2010 03:29 PM
NEED EXPLANATION WHY CODE GIVES ERRORS andylites BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 2 March 24th, 2009 10:06 AM
asp errors with database recordset code dhx10000 Classic ASP Professional 0 June 27th, 2006 12:30 PM
database errors singhzubin PHP Databases 2 April 16th, 2005 05:05 PM
Printing Errors / Example Code Fire BOOK: Access 2003 VBA Programmer's Reference 0 April 12th, 2005 02:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.