witam, już nie mam sił do tego.
VS2005 i C#, do tego mysql i mysql connector. Select z tabeli działa ok, niestety Insert wywala błąd (kompiluje się ale w trakcie działania aplikacji po próbie wstawienia wiersza):
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at MySql.Data.MySqlClient.MySqlCommand.CheckState()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at project4.Form1.button2_Click(Object sender, EventArgs e) in C:\Documents and Settings\TomaszM\Moje dokumenty\Visual Studio 2005\project4\project4\Form1.cs:line 44
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Oto kod przycisku, po którym powinien wykonać się insert:
private void button2_Click(object sender, EventArgs e)
{
string myConnectionString = "Database=test;Data Source=localhost;User Id=root;Password=root";
MySqlConnection myConnection = new MySqlConnection(myConnectionString);
myConnection.Open();
MySqlCommand cmd = new MySqlCommand("INSERT INTO dane VALUES(5,'Jerry')");
<b>cmd.ExecuteNonQuery();</b> // <-- gdy dochodzi tutaj to wywala exception
myConnection.Close();
}
Macie jakiś pomysł?
Pozdrawiam.