Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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 November 1st, 2005, 10:18 PM
Registered User
 
Join Date: Oct 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Help with this code?

  Need help with the following code to run (from the book) keeps failing when it hits objCommand.ExecuteNonQuery()?? New to programming..... Also is there anywhere that I can get some easy to follow code that writes to a data source, because I'm still a bit confused after reading chapter 16. I need more info on displaying reading and writing to a database. Thanks


        Dim objConnection As SqlConnection = New SqlConnection _
        ("server=(local);database=pubs;integrated security=true")

        Dim objCommand As SqlCommand = New SqlCommand
        objCommand.Connection = objConnection
        objCommand.CommandText = "INSERT INTO authors " & _
        "(au_id, au_lname, au_fname, contract) " & _
        "VALUES(@au_id,@au_lname,@au_fname,contract)"

        objCommand.Parameters.Add("@au_id", TextBox1.Text)
        objCommand.Parameters.Add("@au_lname", TextBox2.Text)
        objCommand.Parameters.Add("@au_fname", TextBox3.Text)
        objCommand.Parameters.Add("@contract", CheckBox1.Checked)

        objConnection.Open()
        objCommand.ExecuteNonQuery()
        objConnection.Close()



 
Old November 2nd, 2005, 08:11 AM
Registered User
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what does the error message say when it errors?

Have you set up all the permissions on the database as well

 
Old November 2nd, 2005, 09:11 AM
Registered User
 
Join Date: Oct 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's the error message I get?
_____________________________________________

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: System error.


____________________________________________
thanks for your help

 
Old November 2nd, 2005, 10:12 AM
Registered User
 
Join Date: Oct 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One other note, is it my sql command text thats the problem?
thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM
disable forum code within [code] blocks? nikolai Forum and Wrox.com Feedback 0 October 23rd, 2003 07:52 PM





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