Check if a record exists in the database

前端 未结 13 1746
借酒劲吻你
借酒劲吻你 2020-11-28 12:58

I am using these lines of code to check if the record exists or not.

SqlCommand check_User_Name = new SqlCommand(\"SELECT * FROM Table WHERE ([user] = \'\" +         


        
13条回答
  •  天涯浪人
    2020-11-28 13:31

    MySqlCommand cmd = new MySqlCommand("select * from table where user = '" + user.Text + "'", con);
    MySqlDataAdapter da = new MySqlDataAdapter(cmd);
    DataSet ds1 = new DataSet();
    da.Fill(ds1);
    int i = ds1.Tables[0].Rows.Count;
    if (i > 0) {
        // Exist
    }
    else {
        // Add 
    }
    

提交回复
热议问题