111,094
社区成员




using (SqlConnection conn = new SqlConnection("server=.;database=" + dbName + ";uid=sa;pwd=123456"))
{
try
{
string str_InsertUpdate = string.Format(@"INSERT INTO tb_A (county, date, state) VALUES ('{0}','{1}','{2}') ON DUPLICATE KEY UPDATE state = '{2}'",countyName, dateTime, stateNumber);
SqlCommand comm = new SqlCommand(str_InsertUpdate, conn);
if (conn.State == ConnectionState.Closed)
conn.Open();
int i =
comm.ExecuteNonQuery();
if (i < 1) return false;
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}