Hi,
How can I write correctly codes that values are repeated in the second piece of codes? Why I am asking this question? Just because there are some parameters's values underlined (showing that some values are repeated). But its the real column's name.
For example these two pieces codes are into the same button:
//First piece:
//Second piece:
// Its underline where its colored in red
How can I write correctly codes that values are repeated in the second piece of codes? Why I am asking this question? Just because there are some parameters's values underlined (showing that some values are repeated). But its the real column's name.
For example these two pieces codes are into the same button:
//First piece:
C#:
conn = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\x\\WindowsFormsApplication1\\App_datas\\test.mdf;Integrated Security = True;Integrated Security = True");
comm = new SqlCommand();
if (conn.State != ConnectionState.Open)
conn.Open();
SqlCommand comm = new SqlCommand();
comm1.Connection = conn;
SqlParameter date = new SqlParameter("@date", SqlDbType.VarChar);
SqlParameter name = new SqlParameter("@name", SqlDbType.VarChar);
comm1.Parameters.Add(date);
comm1.Parameters.Add(name);
date.Value = dtDate.Text;
name.Value = txtName.Text;
comm.Connection = conn;
comm.CommandText = "insert into accounting ([date],[name])values(@date,@name)";
{
if (MessageBox.Show("Are you sure to save?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
comm.ExecuteNonQuery();
}
finally
{
conn.Close();
}
//Second piece:
// Its underline where its colored in red
C#:
conn = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\x\\WindowsFormsApplication1\\App_datas\\test.mdf;Integrated Security = True;Integrated Security = True");
comm = new SqlCommand();
if (conn.State != ConnectionState.Open)
conn.Open();
SqlCommand comm = new SqlCommand();
comm1.Connection = conn;
SqlParameter date = new SqlParameter("@date", SqlDbType.VarChar); //here
SqlParameter name = new SqlParameter("@name", SqlDbType.VarChar); // here
comm1.Parameters.Add(date);
comm1.Parameters.Add(name);
date.Value = dtDate.Text;
name.Value = txtName.Text;
comm.Connection = conn;
comm.CommandText = "insert into accounting ([date],[name])values(@date,@name)";
{
if (MessageBox.Show("Are you sure to save?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
comm.ExecuteNonQuery();
}
finally
{
conn.Close();
}
Last edited by a moderator: