Home > Net > C # how to connect only one database, and then perform three query SQL statement, and then take to t
C # how to connect only one database, and then perform three query SQL statement, and then take to t
Time:03-27
I have a database with a total of 30 fields, field called id, field 2, 3, field... Field 30, I want to connect only one database, then in the database query in turn these three kinds of qualified record, find out the record of field 2, field 3,... 30 numerical fields,
1, find the id="xxxxxx01" records, the field 2, the field 3,... Field of 30 numerical ordinal, 2, find the id="xxxxxx02" records, the field 2, the field 3,... Field of 30 numerical ordinal, 3, find the id="xxxxxx04" records, the field 2, the field 3,... Field of 30 numerical ordinal,
here is my code, but there is a problem, please help to correct me,
Try { MySqlConnection COMconn=null; String COMconStr="server=localhost; Port=3306; User Id=root; Password=winelec68331; The database=cableid; Allow the User Variables=True ";//the connection string COMconn=new MySqlConnection (COMconStr); COMconn. The Open ();
//query id="xxxxxx01" records, the field 2, the field 3,... 30 numerical fields in turn out String COM1sql="select * from table1 where id='" +" xxxxxx01 "+"' "; MySqlCommand COM1Cmd=new MySqlCommand (COM1sql COMconn); MySqlDataReader COM1db=COM1Cmd. ExecuteReader (); If (COM1db. Read ()) { Parameters_buffer [0]=the Convert. ToInt32 (COM1db [] "field 2");//- & gt; Remove the field values 2Parameters_buffer [1]=the Convert. ToInt32 (COM1db/" field 3 ");//- & gt; Take out the field of 3 numerical }
//query id="xxxxxx02" records, the field 2, the field 3,... 30 numerical fields in turn out String COM2sql="select * from table1 where id='" +" xxxxxx02 "+"' "; MySqlCommand COM2Cmd=new MySqlCommand (COM2sql COMconn); MySqlDataReader COM2db=COM2Cmd. ExecuteReader (); If (COM2db. Read ()) { Parameters_buffer [2]=the Convert. ToInt32 (COM1db [] "field 2");//- & gt; Remove the field values 2Parameters_buffer [3]=the Convert. ToInt32 (COM1db/" field 3 ");//- & gt; Take out the field of 3 numerical }
//query id="xxxxxx03" records, the field 2, the field 3,... 30 numerical fields in turn out String COM3sql="select * from table1 where id='" +" xxxxxx03 "+"' "; MySqlCommand COM3Cmd=new MySqlCommand (COM3sql COMconn); MySqlDataReader COM3db=COM3Cmd. ExecuteReader (); If (COM3db. Read ()) { Parameters_buffer [4]=the Convert. ToInt32 (COM1db [] "field 2");//- & gt; Remove the field values 2Parameters_buffer [5]=the Convert. ToInt32 (COM1db/" field 3 ");//- & gt; Take out the field of 3 numerical } } The catch (Exception ex) { MessageBox. Show (ex. Message);//output error message } The finally { COMconn. Close (); }