I'm new to C# and I want to simply pull data from SQL database into my C# application in Visual Studios. I have been using a mix of guides to do this but cannot find what is wrong. The code works if I want to recall a table without specifying parameters otherwise it fails.
This is my code currently:
string CS = "Server = server-sql1;Database=Accounts;Trusted_connection=true";
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("ASP_SLINVOICE", con);
//specify that it is a stored procedure and not a normal proc
cmd.CommandType = System.Data.CommandType.StoredProcedure;
//list the parameters required and what they should be
cmd.Parameters.AddWithValue("@varCURRENCY", "USD");
cmd.Parameters.AddWithValue("@invSTART", "0");
cmd.Parameters.AddWithValue("@invEND", "399999");
cmd.Parameters.AddWithValue("@varCURRENCY", "0");
con.Open();
cmd.ExecuteNonQuery();
using(SqlDataAdapter adap = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adap.Fill(dt);
dataGridView1.DataSource = dt;
}
}
This is the error message I get:
