469,281 Members | 2,489 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

how to insert data into mysql through vb.net

seshu
156 100+
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
5 21826
seshu
156 100+
please help me there
Nov 29 '06 #2
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
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
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
9,735 Expert Mod 8TB
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.

Similar topics

2 posts views Thread by Tavish Muldoon | last post: by
10 posts views Thread by Python_it | last post: by
3 posts views Thread by kristof.loots | last post: by
2 posts views Thread by bballr | last post: by
reply views Thread by brianrpsgt1 | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.