By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,365 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,365 IT Pros & Developers. It's quick & easy.

how to insert data into mysql through vb.net

seshu
100+
P: 156
hi everybody
this is seshu i am creating an application for chekin/checkouttime
for that i need to insert data in to mysql for that i know the command in mysql and even how to do in vb.net but the problem is i dont know how to command in vb and update that to mysql
see i was stuck here
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.Odbc
  2.         Dim con As New OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=mydb;UID=root;PWD=mydb:OPTION=03")
  3.         Dim da As New OdbcDataAdapter
  4.         da.SelectCommand = New OdbcCommand("insert into emplogin values('MTI019','venkatesh','venkatesa','venkipinki',null)", con)
  5.         Dim ds As New DataSet
  6.         Dim builder As CommandBehavior = CommandBehavior.SingleRow
  7.         con.Open()
  8.  
  9. 'The Following Line Was Bolded
  10.         Dim builder As OdbcCommand builder
  11.         'Dim cmd As New OdbcCommand("insert into emplogin values()")
  12. da.Fill(ds, "emplogin")
  13.         da.Update(ds, "emplogin")
iam not finding that in vs2005
i mean the command in bold
Nov 27 '06 #1
Share this Question
Share on Google+
5 Replies


seshu
100+
P: 156
please help me there
Nov 29 '06 #2

P: 20
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.Odbc
  2.         Dim con As New OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=mydb;UID=root;PWD=mydb:OPTION=03")
  3.         Dim da As New OdbcDataAdapter
  4.         da.insertCommand = New OdbcCommand("insert into emplogin(field1,field2,field3,field4,field5) values('MTI019','venkatesh','venkatesa','venkipinki',null)", con)
  5.               Dim builder As new OdbcCommand builder(da)
  6.         da.Update(ds, "emplogin")
**********

to select the values from table

da.selectcommand=new odbccommand("select * from emplogin",con)
Dim ds As New DataSet
da.fill(ds)
Dec 15 '06 #3

P: 1
if i want to insert the data by using ODBC through vb.net, how can i do this?i want insert the data from the textbox that i provided..mean that the data with insert to the textbox then can store in the database with is QSL server..thanksss...need help!!!!
Oct 1 '08 #4

P: 2
this is an easy code to connect to a SQL database to insert data....

Expand|Select|Wrap|Line Numbers
  1. import system.data.odbc
  2. import system.configuration  //must be added by add refference
  3. import system.net
  4. import system.text
  5.  
  6.  
  7. dim con as new OdbcConnection
  8. dim cmd as new OdbcCommand
  9. dim da as new OdbcDataAdapter
  10.  
  11. con.connectionstring = getconnection()  //getconnection is an addional method
  12. cmd.connection = con
  13. con.open()
  14. cmd.commandtype = cmd.commandtext
  15. cmd.commandtype = "Insert Into TableName (...,...,...) VALUES ("' + ... + "','" + ... + "','" + ... + "')"
  16.  
  17. da.InsertCommand = cmd
  18.  
  19. cmd.ExecuteNonQuery()
  20. con.Close()
  21. con.Dispose()
  22. cmd.Dispose()
Apr 7 '09 #5

Frinavale
Expert Mod 5K+
P: 9,731
If you are inserting data into your database you need to supply something for the values you are inserting.

The best way to do this in .NET is to use parameters. The OdbcCommand Object has a Parameters property for this purpose.


Please take a look at the article on how to use a database in your program and since you are using ODBC you should check out how to use a database in your program part II.
Apr 7 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.