主窗體Load事件裡丟入以下程式碼(適當改動連線字串和Query語句)stringstrcon="DataSource=127.0.0.1;InitialCatalog=YouDbName;Password=yourpassword;IntegratedSecurity=true";SqlConnectioncon=null;SqlCommandcmd=null;SqlDataReadersdr=null;boolisLogin=false;try{con=newSqlCommand(strCon);cmd=con.CreateCommand();cmd.CommandText=string.Format("select*fromyourTableNamewhereu_Name="{0}"andu_password="{1}"",textBoxUserName.Text,textBoxPassword.Text);con.open();sdr=cmd.ExecuteReader();while(sdr.Read()){isLogin=true;}if(isLogin){MessageBoxShow("loginsucess!!!");}else{MessageBoxShow("loginfail!!!");}}catch(Exceptionex){MessageBoxShow(ex.Message);}finally{sdr.Close();cmd.Close();con..Close();}
主窗體Load事件裡丟入以下程式碼(適當改動連線字串和Query語句)stringstrcon="DataSource=127.0.0.1;InitialCatalog=YouDbName;Password=yourpassword;IntegratedSecurity=true";SqlConnectioncon=null;SqlCommandcmd=null;SqlDataReadersdr=null;boolisLogin=false;try{con=newSqlCommand(strCon);cmd=con.CreateCommand();cmd.CommandText=string.Format("select*fromyourTableNamewhereu_Name="{0}"andu_password="{1}"",textBoxUserName.Text,textBoxPassword.Text);con.open();sdr=cmd.ExecuteReader();while(sdr.Read()){isLogin=true;}if(isLogin){MessageBoxShow("loginsucess!!!");}else{MessageBoxShow("loginfail!!!");}}catch(Exceptionex){MessageBoxShow(ex.Message);}finally{sdr.Close();cmd.Close();con..Close();}