public int GetLastid() { System.Data.SqlClient.SqlDataReader Myreader; int Newid; sqlCommand.CommandText = "SELECT @@IDENTITY as Newid"; Myreader = sqlCommand.ExecuteReader(); Myreader.Read(); Newid = Conversions.ToInteger(Myreader["NewID"]); Myreader.Close(); return(Newid); }
public string ReadCodesForRegion(int regionId) { var strTemp = new StringBuilder(); System.Data.SqlClient.SqlDataReader Myreader; sqlCommand.Parameters.Clear(); sqlCommand.Parameters.AddWithValue("@ID", regionId); sqlCommand.CommandText = "Select code FROM STATIONS WHERE region_id = @ID"; Myreader = sqlCommand.ExecuteReader(); while (Myreader.Read()) { strTemp.Append(Myreader["code"].ToString()); } Myreader.Close(); return(strTemp.ToString()); }
public string GetRegion(int stationId) { string strTemp = ""; System.Data.SqlClient.SqlDataReader Myreader; sqlCommand.Parameters.Clear(); sqlCommand.Parameters.AddWithValue("@ID", stationId); sqlCommand.CommandText = "Select value FROM STATIONS LEFT JOIN REGIONS On REGIONS.ID = STATIONS.region_id WHERE stations.id = @ID"; Myreader = sqlCommand.ExecuteReader(); Myreader.Read(); if (Myreader.HasRows) { strTemp = Myreader["value"].ToString(); } Myreader.Close(); return(strTemp); }
public bool CanDelete(object id) { System.Data.SqlClient.SqlDataReader Myreader; sqlCommand.Parameters.Clear(); sqlCommand.Parameters.AddWithValue("@ID", id); sqlCommand.CommandText = "SELECT id FROM CALLS WHERE priority_id = @ID"; Myreader = sqlCommand.ExecuteReader(); Myreader.Read(); if (Myreader.HasRows) { Myreader.Close(); return(false); } Myreader.Close(); return(true); }
public void FillComboName() { string PdCstr = "datasource = localhost; database=smartcart; username=root; password=apmsetup;"; string Query = "SELECT name FROM product"; MySqlConnection PdconDB = new MySqlConnection(PdCstr); MySqlCommand PDcmdDB = new MySqlCommand(Query, PdconDB); MySqlDataReader Myreader; try { PdconDB.Open(); Myreader = PDcmdDB.ExecuteReader(); while (Myreader.Read()) { string sName = Myreader.GetString("name"); cbBoxPdName.Items.Add(sName); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }