|
-
September 28th, 2006, 02:49 AM
#1
Errors while adding rows to Database
i am working on two databases one is for human resource management and the other is of projects details. my problem is occuring while saving record or deleting record. i've created a form of departments where i am inserting Department_ID, Department_Name and Location when i entered values and press add then there is an erroe of type casting.
i am casting the text values into integer but the problem is still unsolved the code behind add button is :
Code:
Dim drAdd As DataRow
Dim value As Integer
value = CInt(TextBox1.Text)
drAdd = DsDep1.Tables("Departments_Detail").NewRow()
drAdd(0) = value
drAdd(1) = TextBox2.Text
drAdd(2) = TextBox3.Text
DsDep1.Tables("Departments_Detail").Rows.Add(drAdd)
DaDep.Update(DsDep1, "Departments_Detail")
MsgBox("New Record added to the Database")
data types are:
Department_ID = Integer
Department_Name = Varchar
Location = Text
Last edited by HanneSThEGreaT; October 2nd, 2006 at 05:10 AM.
Reason: Added Code Tags
-
September 28th, 2006, 02:56 AM
#2
Re: solve my problem
Welcome to the Forum 
"Solve my Problem" is not a good thread title. Use descriptive thread titles.
Instead of using Cint use Convert.
Code:
Dim value As Integer
value = Convert.ToInt32(TextBox1.Text)
Shouldn't Department_ID be an autonumber?
-
September 28th, 2006, 11:17 AM
#3
Re: solve my problem
I edited the thread title, I hope it is clearer now.
-
September 29th, 2006, 01:51 AM
#4
Re: solve my problem
Hi there,first you can use value=val(TextBox1.Text)
and since Department-ID is not autonumber,and it's preferable,try to bring always max(department_ID) by a query and then add to it +1,so u have to let your TextBox empty and disable,befor the save bring the max(....) addto it 1 and put it in the textbox..........
-
October 5th, 2006, 08:11 AM
#5
Re: Errors while adding rows to Database
Except in a multi-user system, where max+1 is silly unless it is being run as part of the insert statement
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|