Please anyone give me the code for how to save data
give me the code for how to save data into database my back end is mysql and also how to write the code of auto increment id???
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sunny SharmaRank #223 · 11.1K reputationPosted Jun 25, 2013, 1:59 AM EDT
To use MySql Database in C#, download and install MySql .NET connector from here:
http://dev.mysql.com/downloads/connector/net/
After you finish installation,add reference to MySql.Data.dll and add namespace as:
Using MySql.Data.MySqlClient;
Syntax for ConnectionString is as follows:
"Server=localhost;uid=username;password=pwd;database=test;pooling=false;"
Below is a sample code snippet which will enable you to connect and perform operations on MySql Database:
//Create and initialize the connection and command
MySqlConnection conn = new MySqlConnection(connectionString);
MySqlCommand cmd = new MySqlCommand("select * from table", conn);
try
{
conn.Open();
}
catch(Exception ex)
{
// Database connection error;
}
if (conn.State == ConnectionState.Open) //ConnectionState Enum is contained in System.Data namespace
{
//Perform operations here
{
cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
//Handle exception here
}
}
if (conn.State == ConnectionState.Open)
{
try
{
conn.Close();
}
catch { }
}
--------------------------------------------------------------------
Happy Coding :)
Mark it as answer if it helps.
Cheers!
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jun 25, 2013, 2:00 AM EDT
http://www.c-sharpcorner.com/uploadfile/iamibohal/how-to-connect-mysql-server-with-Asp-Net-2005-2008-C-Sharp/
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
Ravi ShekharRank #673 · 3.6K reputationPosted Jun 25, 2013, 2:34 AM EDT
http://www.w3schools.com/sql/sql_autoincrement.asp
and
http://learneveryday.net/asp-net/mysql/insert-in-to-mysql-with-asp-net-part-1/
Mark it as answer if it helped you.
shoaib shaikh8 reputationPosted Jun 25, 2013, 7:09 AM EDT