Hi All,
Have come back to programming after a lengthy break for a personal project using visual c# and SQL Server Express in a win forms app.
The problem I have is that my INSERT INTO statements are not working, while my SELECT statements are working perfectly.
While debugging the command seems to fire just fine, ExecuteNonQuery() returns 1 and no exception caught. But when looking at the table there is NO DATA!! Have tried obvious things like refreshing the table and restarting Visual c#. Still no data...
Any ideas greatly appreciated. Thanks in advance.
Xavi
Method here if it helps:
public static void addSymbol(string symbolCode, string securityName)
{
SqlConnection con = RM1.Classes.StaticData.GetConnectionString;
SqlCommand com = new SqlCommand("INSERT INTO symbol (symbolCode, securityName) VALUES (@symbolCode, @securityName)", con);
com.CommandType = System.Data.CommandType.Text;
com.Parameters.AddWithValue("@symbolCode", symbolCode);
com.Parameters.AddWithValue("@securityName", securityName);
int records = 0;
try
{
con.Open();
records = com.ExecuteNonQuery();
Console.WriteLine(records + " symbols added");
}
catch (Exception ex)
{
Console.WriteLine("Add symbol failed" + ex.ToString());
}
finally
{
con.Close();
}
}
Have come back to programming after a lengthy break for a personal project using visual c# and SQL Server Express in a win forms app.
The problem I have is that my INSERT INTO statements are not working, while my SELECT statements are working perfectly.
While debugging the command seems to fire just fine, ExecuteNonQuery() returns 1 and no exception caught. But when looking at the table there is NO DATA!! Have tried obvious things like refreshing the table and restarting Visual c#. Still no data...
Any ideas greatly appreciated. Thanks in advance.
Xavi
Method here if it helps:
public static void addSymbol(string symbolCode, string securityName)
{
SqlConnection con = RM1.Classes.StaticData.GetConnectionString;
SqlCommand com = new SqlCommand("INSERT INTO symbol (symbolCode, securityName) VALUES (@symbolCode, @securityName)", con);
com.CommandType = System.Data.CommandType.Text;
com.Parameters.AddWithValue("@symbolCode", symbolCode);
com.Parameters.AddWithValue("@securityName", securityName);
int records = 0;
try
{
con.Open();
records = com.ExecuteNonQuery();
Console.WriteLine(records + " symbols added");
}
catch (Exception ex)
{
Console.WriteLine("Add symbol failed" + ex.ToString());
}
finally
{
con.Close();
}
}