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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
shoaib shaikhPosted Jun 25, 2013, 11:09 AM
Ravi ShekharPosted Jun 25, 2013, 6:34 AM
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.
Sanjeeb LenkaPosted Jun 25, 2013, 6:00 AM
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
Sunny SharmaPosted Jun 25, 2013, 5:59 AM
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
MySqlCommand cmd = new MySqlCommand("INSERT INTO myTable values (...);", mycon);try{
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!