| | |
Insert Command problem in vb.net using OleDb
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 23
Reputation:
Solved Threads: 0
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()
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()
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
Something to that effect
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)
Dim var As Date 'Declare a date variable var = DateTimePicker1.Value.Date 'Get the date! dr("BirthDate") = var
Something to that effect
Michelle (Junior Developer)
![]() |
Similar Threads
- UPDATE query problem (ASP.NET)
Other Threads in the VB.NET Forum
- Previous Thread: ScreenHeiht
- Next Thread: Playing wav file
| Thread Tools | Search this Thread |
"crystal .net .net2005 2008 access add advanced application array assignment basic beginner box button buttons center click client code combo convert cpu data database datagrid datagridview designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall forms html image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web winsock wpf wrapingcode xml





