Ik ben bezig met een programma te schrijven in c#. Maar ik krijg steeds errors in mijn insert functie:
using System.Data.SqlClient;
string conn = "Data Source=SQLEXPRESS;Initial Catalog=MMG;Integrated Security=SSPI;";
SqlCommand cmd = new SqlCommand("INSERT INTO MMG VALUES (Jaap, Stam,);", conn);
Errors:
Error 1 A field initializer cannot reference the non-static field, method, or property 'Mmg.Form1.conn' C:\Users\*****\Documents\Visual Studio 2008\Projects\Mmg\Mmg\Form1.cs 25 82 Mmg
Error 2 The best overloaded method match for 'System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)' has some invalid arguments C:\Users\Joost Oostburg\Documents\Visual Studio 2008\Projects\Mmg\Mmg\Form1.cs 25 26 Mmg
Error 3 Argument '2': cannot convert from 'string' to 'System.Data.SqlClient.SqlConnection' C:\Users\Joost Oostburg\Documents\Visual Studio 2008\Projects\Mmg\Mmg\Form1.cs 25 82 Mmg
vage ado.net
heb al zoveel geprobeerd ben ik nou echt zo een noob?
using System.Data.SqlClient;
string conn = "Data Source=SQLEXPRESS;Initial Catalog=MMG;Integrated Security=SSPI;";
SqlCommand cmd = new SqlCommand("INSERT INTO MMG VALUES (Jaap, Stam,);", conn);
Errors:
Error 1 A field initializer cannot reference the non-static field, method, or property 'Mmg.Form1.conn' C:\Users\*****\Documents\Visual Studio 2008\Projects\Mmg\Mmg\Form1.cs 25 82 Mmg
Error 2 The best overloaded method match for 'System.Data.SqlClient.SqlCommand.SqlCommand(string, System.Data.SqlClient.SqlConnection)' has some invalid arguments C:\Users\Joost Oostburg\Documents\Visual Studio 2008\Projects\Mmg\Mmg\Form1.cs 25 26 Mmg
Error 3 Argument '2': cannot convert from 'string' to 'System.Data.SqlClient.SqlConnection' C:\Users\Joost Oostburg\Documents\Visual Studio 2008\Projects\Mmg\Mmg\Form1.cs 25 82 Mmg
vage ado.net