473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 22134
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

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

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
2
by: Atz | last post by:
Hi to all ! Im using MySql front and PHP 5 for some web shop. I didn't try it so far but i guess that the online data insertation ( accept costs and time ) should be the same process like for...
2
by: Tavish Muldoon | last post by:
What a pain trying to insert data into a table from a stored proc. My webform asks for 16 pieces of data - which then gets written to the database. I found this easier than the crap below...
10
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
3
by: kristof.loots | last post by:
Hi all, Somehow I want to transfer data from an mysql database on the web to an local offline access database. Note: tables and types do not match. So, I toughed, generating sql commands to...
1
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. ...
2
by: bballr | last post by:
I have a problem that I'm not sure if it can be done. I'm trying to use the MySQL C API to be able to use a normal sql insert statement that will send the data or file to a directory and NOT the...
2
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to...
6
by: TheRealDan | last post by:
Hi all. I'm having a problem with a special characters. I have php script that reads from an xml file and writes to a mysql db. It's a script called phptunest that I found on the net, although the...
0
by: brianrpsgt1 | last post by:
I am attempting to insert data from a HTML form using a .psp script. I can not find how to link the data that is inserted into the form to the variables in the .psp script to then insert into the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.