I\'m coming over from PHP and am having a hard time with storing information into my newly created local database. I\'m using Microsoft Visual C# 2010 to help me learn and devel
Here's some code that uses SQLServer to do a direct insert, although you'll need a connection string to your database.
Include the SQL server database includes.
using System.Data.SqlClient;
using System.Data.SqlTypes;
. . .
using (SqlConnection cn = new SqlConnection("XXXXX")) // must put a connection string to your database here
{
cn.Open();
using (SqlCommand cmd = new SqlCommand("INSERT INTO Session(field1, field2) VALUES(@Value1, @Value2)"))
{
cmd.Parameters.AddWithValue("@Value1", 4);
cmd.Parameters.AddWithValue("@Value2", "test");
cmd.ExecuteNonQuery();
}
}