conn.Open();//open the channels, establishing connection
MessageBox. Show (" database connection ");
//search phone number
MySqlCommand comm=new MySqlCommand (" select * from yh1 where num1=158 ", conn);
MySqlDataReader reader=comm. ExecuteReader ();
MessageBox. Show (" checked ");
conn.Close();
Bool hr=reader. HasRows;
If (reader. HasRows)
{MessageBox. Show (hr. The ToString ()); }
//there is no phone number, register
The else
{MessageBox. Show (hr. The ToString ()); }
String wre=the string. Format (" insert yh1 (num1) values (' 151 ') ");
conn.Open();
//
MySqlCommand zhuce=new MySqlCommand (wre, conn);
Zhuce. ExecuteNonQuery ();
Kaile MessageBox. Show (" ");
conn.Close();
}
Catch
{MessageBox. Show (" write failure ");
}
CodePudding user response:
CodePudding user response:
CodePudding user response:
CodePudding user response:
The unusually,,, conn are you closed, reader can't directly access, read your shut againBool hr=reader. HasRows;
conn.Close();
CodePudding user response:
Finally close connections in the codeCodePudding user response:
It is ok to delete the first close, database connection is closed also check?CodePudding user response:
Database connection open cost is higher, once opened, after query all shut down again,CodePudding user response:
This really don't understandCodePudding user response:
Novice said what all don't understand,,,,CodePudding user response:
See don't understand still thank youCodePudding user response:
So, I seeCodePudding user response:
Use WCF? ,,,,,,,CodePudding user response:
First sqldatareader is read-only, and can only be read under the status of the database connectionThe
MessageBox. Show (" checked ");
conn. Close (); Delete
Bool hr=reader. HasRows;
In addition, you always output "to failure", need to change to the following
String wre=the string. Format (" insert into the yh1 (num1) values (' 151 ') ");
conn.Open();
Remember to "post!
CodePudding user response:
So, I seeCodePudding user response:
Could you explain comm query principle? In addition, conn connection point can target? Look at the code, as you want to access to a nonexistent resources, but have not get the correct error message,CodePudding user response:
You are close, and reader?