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 June 3rd, 2005, 05:01 AM
Authorized User
 
Join Date: Mar 2004
Posts: 33
Thanks: 0
Thanked 1 Time in 1 Post
Default PrimaryKeys, AutoIncrement

The primarykey in my general_billing table is autoincrement but when i call the function to add to the database, thy primarykey column wont autoincrement. Can some please give direction?

call from UIClass
   g_billing = new GeneralBilling(Nothing, "test","test", "test")

Dim connection As New Connection
        connection = New Connection
        MsgBox(getID)
        Dim sql_insert As String = "INSERT INTO general_billing"
"(serviceID, service_name, measurement_unit, cost) VALUES (" & _
           getID() & ", '" & getName & "', '" & getUnit & "', " & getCost & ");"
---------------------
general_billing.vb

connection.ConnectToDB(sql_insert)
__________________
gbilios
 
Old June 4th, 2005, 12:37 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

if the primary key is autoincrement, you dont need to pass the value in the sql statement.
Code:
Insert Into general_Billing (service_name, measurement_unit, cost)
Values ('name', 10, 10)
Regards
Ganesh
 
Old June 4th, 2005, 08:56 AM
Authorized User
 
Join Date: Mar 2004
Posts: 33
Thanks: 0
Thanked 1 Time in 1 Post
Default

I get a syntax error. Since i omitted the USerID(primary key), the insert statement fails. I am also using Ms Access and i tested the insert statement and didn't work. I added the insert statement in case anyone can tell me what is wrong.

Dim sql_insert As String = "INSERT INTO t_user(EmployeeID, username, password, level) VALUES(" & emp.getID() & ", '" & username & "', '" & password & "', " & level & ");"
connection.ConnectToDB(sql_insert)
 
Old June 7th, 2005, 08:14 AM
Authorized User
 
Join Date: Mar 2004
Posts: 33
Thanks: 0
Thanked 1 Time in 1 Post
Default

heres the problem. the system didn't like the names username and password and so i changed it to t_username and t_password and level to a_level.

that worked.
 
Old June 9th, 2005, 07:31 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

you can put the field names as [UserName] and [Password] to solve that issue, if you want to use the same names

Regards
Ganesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
dataset and autoincrement primary key be03024 ADO.NET 8 July 19th, 2009 12:09 PM
AutoIncrement Aaron Edwards ASP.NET 2.0 Basics 5 February 7th, 2007 02:37 PM
setting autoincrement tbecker82 Access 3 June 20th, 2006 01:17 PM
Generated dataset and autoincrement dbradley ADO.NET 5 February 2nd, 2005 01:14 AM
Autoincrement field not incrementing leo_vinay SQL Server ASP 1 January 4th, 2005 08:07 AM





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