943,614 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 5168
  • VB.NET RSS
Sep 18th, 2008
0

Insert Command problem in vb.net using OleDb

Expand Post »
Hello there.....i just learnt how to use the the oleDb commands to insert into the a database i created from vb.net,but the problem is.....i cannot insert anythin else than OleDbType.VarChar
or i dunno how to insert anything else

this is my code......i need help to insert the value of my datetimepicker to my database

DatAdapter.InsertCommand = New OleDbCommand("INSERT INTO Staff(StaffName,BirthDate,Gender,Address,Phone,Position,StaffID,SystemPassword) VALUES(@StaffName,@BirthDate,@Gender,@Address,@Phone,@Position,@StaffID,@SystemPassword)")
DatAdapter.InsertCommand.Parameters.Add("@StaffName", OleDbType.VarChar, 40, "StaffName")
DatAdapter.InsertCommand.Parameters.Add("@BirthDate", OleDbType.Date, 20, "BirthDate")
DatAdapter.InsertCommand.Parameters.Add("@Gender", OleDbType.VarChar, 40, "Gender")
DatAdapter.InsertCommand.Parameters.Add("@Address", OleDbType.VarChar, 40, "Address")
DatAdapter.InsertCommand.Parameters.Add("@Phone", OleDbType.VarChar, 40, "Phone")
DatAdapter.InsertCommand.Parameters.Add("@Position", OleDbType.VarChar, 40, "Position")
DatAdapter.InsertCommand.Parameters.Add("@SystemPassword", OleDbType.VarChar, 40, "SystemPassword")


DatAdapter.InsertCommand.Parameters.Add("@BirthDate", OleDbType.Date, 20, "BirthDate")

Then My button where all is executed

Dim dr As DataRow
dr= ds.Tables(0).NewRow()

dr("StaffName") = TextBox2.Text
dr("BirthDate") = DateTimePicker1.Value
dr("Gender") = ComboBox1.Text
dr("Address") = TextBox3.Text
dr("Phone") = TextBox4.Text
dr("Position") = ComboBox2.Text
dr("StaffID") = FirstPass.Text
dr("SystemPassword") = SecondPass.Text

ds.Tables(0).Rows.Add(dr)
DatAdapter.Update(ds)
ds.AcceptChanges()
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
gopi17 is offline Offline
39 posts
since Sep 2008
Sep 19th, 2008
0

Re: Insert Command problem in vb.net using OleDb

Hi ... im fairly new to this aswell so ...

if the date field in your database is set to dateTime then you have to add the date selected from the dateTimePicker in date format

VB.NET Syntax (Toggle Plain Text)
  1. Dim var As Date 'Declare a date variable
  2. var = DateTimePicker1.Value.Date 'Get the date!
  3.  
  4. dr("BirthDate") = var

Something to that effect
Reputation Points: 30
Solved Threads: 0
Junior Poster in Training
Elmo_loves_you is offline Offline
85 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: ScreenHeiht
Next Thread in VB.NET Forum Timeline: Playing wav file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC