473,554 Members | 3,199 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to insert data into mysql through vb.net

seshu
156 New Member
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 22147
seshu
156 New Member
please help me there
Nov 29 '06 #2
siricharan82
20 New Member
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.selectcomman d=new odbccommand("se lect * from emplogin",con)
Dim ds As New DataSet
da.fill(ds)
Dec 15 '06 #3
outsider5486
1 New Member
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..thankss s...need help!!!!
Oct 1 '08 #4
blackshadow29
2 New Member
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 Recognized Expert Moderator Expert
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
7371
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 atmosphere. Good food.", " (Harry Houdini - 03/01/2004)"); INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada", " (Herbert Hoover -...
2
2833
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 local connection. Problem: I have to create online ( on remote server ) some 6 tables and some 20 fields with MySql front. Ok. This shouldn't be...
2
4177
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 (after the ***********). This was eaiser: get a list of all the parameters you want to pass - put them in a string:
10
52462
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 string or NULL. Becaus i have a if statement: if .... cursor.execute(".................insert NULL ..............") if ....
3
17914
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 insert the data would do the trick. But, unfortunately it works only properly for 1 record. This is what I do (suggestions are more than welcome)...
1
5393
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. And the line it shows in red is cmd.ExecuteNonQuery()
2
1693
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 database. I'm not sure if there is anything out there that will allow this, but I've searched everywhere, and I have found no solution. If anyone...
2
7028
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 find syntax to insert values into a mysql database table. I'm able to use the below syntax to insert hard-coded values like 'josie' and 'smith' but...
6
3863
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 original website for the author appears to be gone. It works really nicely except when it hits special characters. Everything from a sp char...
0
3344
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 MySQL Insert statement. I am familiar with PHP, where you would write $_POST(), however I can not find the equivalent in PSP. I believe that this...
0
7507
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7783
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8019
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6127
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5424
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5143
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1115
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.