.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Having Trouble Inserting into a MySQL Database

Posted By:      Posted Date: October 14, 2010    Points: 0   Category :ASP.Net


I was recently using an Access Database for a .NET application however, I was coming across the problem that it wasn't allowing me to Insert any new data into the table.  So, I switched to a MySQL database but I am encountering the same issues.  Below is my could in which the information is gathered and submited to the table.  Thanks in advanced for your help.

Protected Sub AddProd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddProd.Click

 Dim pid As String
 pid = Request.QueryString("pid")

  Dim conn As New OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver}; SERVER=*server*; PORT=3306; DATABASE=*database*; UID=*user*; PASSWORD=*password*; OPTION=3;")

 Dim query As New OdbcCommand("SELECT Price, Shipping FROM Products WHERE ItemNum = '" & pid & "'", conn)


 Dim reader As OdbcDataReader = query.ExecuteReader

 If reader.Read() Then

 Dim Today As String
 Today = Date.Today

 Dim IP As String
 IP = Request.ServerVariables("REMOTE_HOST")

 Dim Price As Double = reader.Item("Price")

 Dim Shipping As Double = reader.Item("Shipping")


 Dim ItemNum As String = pid

 Dim Quanity As String = Request.Form("txtQuanity")

 Dim EngraveLine1 As String = ""
 Dim EngraveLine2 As Strin

View Complete Post

More Related Resource Links

LINQ to SQL - Validating if item is in Database, but if item is not items not inserting into databas



I am new to this, so bear with me.  I am writing an application in C# that uses LINQ to validate a datacontext off a textbox to see if the record exists already.  If the record does exist I inserted an if statement to advise the user that the record exists, if the record does not exist I would like to allow the record to be added to the database.  If I take out my else statement everything works fine as far as inserting goes, but I do not want to allow inserts in this scenario.  I have tried moving the if and else statement to different parts of the code but can't quite figure this one out.  Any help would be apprecaited, attached is the code.  This code is set to a button press.  As a matter of fact, if you see any other errors along the way please feel free to point them out. 



    protected void enterBTN_Click(object sender, EventArgs e)
        //make new data context

        SHCDataContext insNewAll = new SHCDataContext();
        //LINQ to check if customer exists in database
        var checkExisting = from c in insNewAll.Customers
                            where c.custLastName.Contains(custLastNameTB.Text.ToString())
                            select c.custLastName;
        //make list to store values

search in mysql database, mvc



I have set up a mysql connection in visual studio 2010 and now i have a connection and dont really know where to go next.

I want to be able to search the data and get the result in a view.

using asp.net mvc

Saving textbox data to MySql database in asp.net


Hi dear coders

though a very simple question to ask, but please tell me how to save and retrieve data in/from my textboxes to/from database (MYSQL) on submit button click.

i know its a very simple task but i cant make it done, so i request you to please send me some working example link or post any helpful code here in asp.net

i will be highly thankful for any kind help from you geniuses.



get the last inserted row ( autoincrement id ) in mysql database back


In my mysql I have an autoincrement id , whenever I add a new row into database I need to store this id in other table, so how to get this autoincrement Id back?

Issue inserting to database on submit the page goes blank

Hi guys,I'm new to asp.net, can someone please help me with this. I'm trying to insert few values to a table, when i press the submit button the aspx page goes blank and i don't get any error message. I'm not able to find where the error is.The code:Protected Sub AddMInfo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddMInfo.Click Dim dbsource As SqlDataSource dbsource = New SqlDataSource         dbsource.ConnectionString = ConfigurationManager.ConnectionStrings("dbConnectionString1").ToString         dbsource.InsertCommandType = SqlDataSourceCommandType.Text         dbsource.InsertCommand = "INSERT INTO db_mdl_info(dlprodid,dlmdlid,dlbrnd,dlmdlnm,dlmdlnbr,dlcpst,dlprsr,dlmxm,dlmim,dlmslt,dlmxps,dlmtpe)" &                                 "Values('" & DropDownList2.Text & "','" & DropDownList3.Text & "','" & MakeTextBox.text & "','" & DropDownList2.SelectedItem.Text &                                 "','" & MNoTextBox.Text & "','&quo

Display records in bold coming from mysql database

hi,I have Mysql database.In that some records status is New.now,I bind database table to Listview(asp) control.What's my problem is,the New status records(from Mysql database) text in Listview(after binding) is visible in bold format.how to do this??Thanks in advance.

inserting an array of data into a database table

im looking to insert an array of information into a database tableessentially what id like to do is something like this:            objCmd = New OleDb.OleDbCommand("INSERT INTO pluINFO VALUES *", objConn)            For j = 0 To 265                objCmd.Parameters.Add( info(j) )            Next this code gives me a syntax error for the insert statement is there anyway i can set the insert statement that would allow me to add each element of the array(looping through rather than hardcoding several hundred entries) into the table?any input appreciatedThanks

Trouble Connecting to a Database

I downloaded a sample DB from here: http://msftdbprodsamples.codeplex.com/releases/view/4004   Specifically, this is the ‘ AdventureWorksLT.msi ’ So, I loaded it into my SSMSE, right-click Databases > Attach > Database > Attach > etc., etc.   Now, in C# (Express) I goto Add new Datasource > Database > Next > New Connection > Browse . . . navigate to the folder that holds the AdventureWorksLT.mdf Select it and click Open and then I get this message: AdventureWorksLT_Data You don’t have permission to open this file Contact the file owner or an administrator to obtain permission.   I don’t think I’ve ever seen this message before, and I am the administrator.  What am I doing wrong here?  Also, what so I need to do to get this working? Thanks! Ryan---

WPF client application connected to an ASP mySQL database

Dear all, I have a customer who is using an online ASP applciation which provide different type of application. My customer run this app within a browser or a simple local client app which s connected to a remote database accessible via an ADSL connection. Today my customer ask me to build a touch client application and collect those data based on different criteria. According to information I have today it seems that the database is mySQL ( not usre at 100%) In case it is mySQL, does any one has made a kind a gateway between mySQl and .net app when database is hosted remotely ? thnaks for advise if any regards SergeYour knowledge is enhanced by that of others.

Code to get details from joomla MYSQL database in godaddy

I want to write a basic code to connect to joomla MY SQL database. I am getting issues with connection string. Can any one help me out with sample code if you did such work before. A simple code which retrives records and displayes in webform is what I require.   Thanks in advance Chandra 

Inserting images into mysql data using c#

hey dere,is dere any way that i can store or insert  images into the mysql database and retrieve them successfully just like textual data.thnks in advance...

Can I create an ADO.NET Entity Data Model for a MySQL database using Visual Web Express 2010?


Can I create  an  ADO.NET Entity Data Model for a MySQL database using Visual Web Express 2010?

If yes, are there any documentation or tutorials?


How do you create a ADO.NET Entity Data Model for a MySQL database using Visual Web Express 2010?


Can I create a ADO.Net Entity Data Model for a MySql(5.0.1) Database using a Visual Web Express 2010? If yes, can anyone please let me know how to do this.

Need help with uploading a text file in to mysql database


I want to upload a text file and stored to my database. the column on my database it is longblob type. I don't know much about this so if anyone can help I will thank you. 

Incremental data load from MySQL database to SQL server 2008 using SSIS


I am looking for best solution to perform incremental data load from MySQL database to SQL Server 2008.  I tried to follow instructions from articles on incremental data load in SSIS  using MD5 hashes but I failed to make connection in Lookup transformation editor between MySQL Id (4 byte unsigned integer) and Id in SQl Server 2008 table which is  bigint. i tried to add  data conversion and convert MySQl Id to string. It works fine when you map this field directly to OLEDB destination but in Lookup component it failed. 


Any input greatly appriciated.



MySql Database back


I developed a software in ASP.ne-VB.net with MySql as database, I wanted to back up the database every end of the day,how to backup and restore the MySQL Database

why two records are inserting in database using Entity Framework??



i am using entity framework to access the database to insert/fetch data from database.

consider i am having two tables "AssetCheckList" and "TaskRecheckDetails"

AssetChecklist  Table






ParentAssetChecklistiID - Forigen Key of AssetCheckListID

RecheckAssetChecklistID -  Forigen Key of AssetCheckListID


when inserting the data in TaskRecheckDetails table two records are inserted with same details.

why and how to resolve it.


please help.




ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend