3
Reply

finding error

khan

khan

Apr 3 2008 11:17 PM
2.6k

hi all,

i get error in my application .plz help to recover the error


i add time in the database .before adding in database it
check this time is already exit or not .if exits it don't allow
me to add the same time again

i have two comobox one for hour and second for minute and it contain
int value.i get value from comobox and concatenate both value
and send to database

on running application it give me system error message

private void btnAdd_Click(object sender, System.EventArgs e)
        {
    //cbxHr.Text hour combo box
    //cbxMin.Text min combo box  
    SaveTiming(cbxHr.Text,cbxMin.Text);
            }

           
    private void SaveTiming(string hr, string std_min)
        {
    bool flag = false;
    string connectionString = "Integrated Security=SSPI;Persist    Security Info=False;Initial Catalog=Testing;Data Source=(local)";
    string  test = hr+""+ std_min;
           
string isExist = "SELECT * FROM timing WHERE s_time=" + test + "";
string sqlInst = "Insert into timing(s_test)Values(" + test + ")";
           
using (SqlConnection connection = new SqlConnection(connectionString))
            {
    SqlCommand command = new SqlCommand(isExist, connection);
    connection.Open();
    SqlDataReader reader = command.ExecuteReader();
    if (reader.HasRows)
    {
    MessageBox.Show("Timing already has been assigned");
    flag = true;
                }
    reader.Close();
       if (!flag)
                {
        SqlCommand cmd = new SqlCommand(sqlInst, connection);
                    cmd.ExecuteNonQuery();
                   
                }
            }
        }

   

 

 


Answers (3)