I am using mysql server 2012 and visual studio 2012 C#, i created a database and i can read the data from my database.
The problem is that i cannot insert data into my database. Although the return value of the execution is 1, i dont see any changes in the table. I executed the same query inside the database explorer and it works.
Anyone can help me??
CODE:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace database
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con;
private void Form1_Load(object sender, EventArgs e)
{
con = new SqlConnection();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\myworkers.mdf;Integrated Security=True;User Instance=True";
con.Open();
MessageBox.Show("OPEN!");
SqlCommand thiscommand = con.CreateCommand();
thiscommand.CommandText = "SELECT * FROM player_info"; /*The data was shown correctly*/
SqlDataReader thisReader = thiscommand.ExecuteReader();
while (thisReader.Read())
{
MessageBox.Show(thisReader["player_name"].ToString());
}
thisReader.Close();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int x;
SqlCommand thiscommand = con.CreateCommand();
thiscommand.CommandText = "INSERT INTO player_info(player_id, player_name) VALUES (1000, 'chene')";
x = thiscommand.ExecuteNonQuery(); /*The return value is 1, but i dont see any changes inside the table. :( */
MessageBox.Show(x.ToString());
con.Close();
}
}
}