public DataTable ExecuteRead(string s) { CDBInfo dbinfo = new CDBInfo(); SqlConnection cnn = new SqlConnection(); cnn.ConnectionString = dbinfo.ConnectString(); //SqlCommand cmd = new SqlCommand(); //cmd.Connection = cnn; //cmd.CommandText = s; DataTable dt = new DataTable(); DataSet ds = new DataSet(); try { SqlDataAdapter sda = new SqlDataAdapter(s, cnn); sda.Fill(ds); dt = ds.Tables[0]; } catch { ds = null; } return(dt); }
public bool MultiExecuteNoneReturn(string[] sqls) { CDBInfo dbinfo = new CDBInfo(); SqlConnection cnn = new SqlConnection(); cnn.ConnectionString = dbinfo.ConnectString(); cnn.Open(); SqlTransaction st = cnn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cnn; cmd.Transaction = st; try { foreach (string item in sqls) { cmd.CommandText = item; cmd.ExecuteNonQuery(); } st.Commit(); } catch { st.Rollback(); return(false); } return(true); }
public int ExecuteNoneReturn(string s) { CDBInfo dbinfo = new CDBInfo(); SqlConnection cnn = new SqlConnection(); cnn.ConnectionString = dbinfo.ConnectString(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cnn; cmd.CommandText = s; try { cnn.Open(); int i = cmd.ExecuteNonQuery(); return(i); } catch (Exception ex) { //MessageBox.Show(ex.ToString() + "\r" + s); return(-1); } }