The following code snippet provides an idea to use MySql in ADO.Net
{code} //for record in databases.. MySqlConnection objconnection = new MySqlConnection("server=localhost;uid=root;password=maa;database=taresh"); MySqlCommand objcommand = new MySqlCommand("", objconnection); objcommand.Parameters.Add("?itemCode",MySqlDbType.VarChar,15); objcommand.Parameters.Add("?itemName", MySqlDbType.VarString, 25); objcommand.Parameters.Add("?Rate", MySqlDbType.Double, 10); objcommand.Parameters.Add("?supp", MySqlDbType.VarString, 25); objcommand.CommandText = "insert into item values(?itemCode,?itemName,?Rate,?supp)"; objcommand.Parameters["?itemCode"].Value=txtItemCode.Text.ToUpper(); objcommand.Parameters["?itemName"].Value = txtItemName.Text.ToUpper(); objcommand.Parameters["?Rate"].Value = txtItemRate.Text.ToUpper(); objcommand.Parameters["?supp"].Value = txtSuppliersName.Text.ToUpper(); //objcommand.CommandText = command; try { objcommand.ExecuteNonQuery(); MessageBox.Show("Record Added"); } catch (MySqlException ex) { MessageBox.Show(ex.Message); }
Following points should be kept in mind : 1. MySql Database Server must be installed [refer to site:http://dev.mysql.com/downloads/index.html] 2. Should be configured. 3. For more details refer to article published in : http://www.15seconds.com/issue/050210.htm
|
No responses found. Be the first to respond and make money from revenue sharing program.
|