Click here to Skip to main content
15,899,679 members
Home / Discussions / Database
   

Database

 
GeneralRe: Loading Data on Demand Pin
Eddy Vluggen1-Jun-17 0:35
professionalEddy Vluggen1-Jun-17 0:35 
AnswerRe: Loading Data on Demand Pin
Jörgen Andersson31-May-17 22:18
professionalJörgen Andersson31-May-17 22:18 
GeneralRe: Loading Data on Demand Pin
Richard Andrew x6416-Jun-17 11:20
professionalRichard Andrew x6416-Jun-17 11:20 
QuestionSQL server: How to get backup file information using SMO Pin
w1424326-May-17 17:52
w1424326-May-17 17:52 
AnswerRe: SQL server: How to get backup file information using SMO Pin
Eddy Vluggen2-Jun-17 1:44
professionalEddy Vluggen2-Jun-17 1:44 
QuestionHow to create SQL Server backup folder Pin
w1424326-May-17 17:44
w1424326-May-17 17:44 
QuestionSSRS - dynamic columns depending on client parameter Pin
Danpeking24-May-17 23:33
Danpeking24-May-17 23:33 
QuestionSql server: create table with column that support unique and multiple nulls Pin
w1424323-May-17 20:03
w1424323-May-17 20:03 
AnswerRe: Sql server: create table with column that support unique and multiple nulls Pin
Maciej Los23-May-17 20:27
mveMaciej Los23-May-17 20:27 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
w1424323-May-17 20:45
w1424323-May-17 20:45 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
Richard Deeming24-May-17 8:22
mveRichard Deeming24-May-17 8:22 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
w1424324-May-17 17:32
w1424324-May-17 17:32 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
Richard Deeming25-May-17 0:51
mveRichard Deeming25-May-17 0:51 
AnswerRe: Sql server: create table with column that support unique and multiple nulls Pin
ZurdoDev24-May-17 3:15
professionalZurdoDev24-May-17 3:15 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
Richard Deeming24-May-17 8:19
mveRichard Deeming24-May-17 8:19 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
ZurdoDev24-May-17 8:24
professionalZurdoDev24-May-17 8:24 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
w1424324-May-17 17:45
w1424324-May-17 17:45 
GeneralRe: Sql server: create table with column that support unique and multiple nulls Pin
ZurdoDev25-May-17 0:49
professionalZurdoDev25-May-17 0:49 
QuestionDisplay data only from search parameters Pin
rattlerrFx23-May-17 7:16
rattlerrFx23-May-17 7:16 
QuestionRe: Display data only from search parameters Pin
CHill6023-May-17 10:52
mveCHill6023-May-17 10:52 
AnswerRe: Display data only from search parameters Pin
rattlerrFx23-May-17 13:21
rattlerrFx23-May-17 13:21 
GeneralRe: Display data only from search parameters Pin
CHill6024-May-17 1:06
mveCHill6024-May-17 1:06 
Here is an example using a ComboBox and a TextBox. I've used a ComboBox with fixed entries for the user to choose from. I don't want them to enter the column name for a few reasons: They might misspell it, they might introduce other errors and because I'm using string concatenation to get the column name (only the name, NOT the value) it provides a further protection against SQL Injection.
C#
private void button1_Click(object sender, EventArgs e)
  {
      if (cmbColumns.SelectedIndex == -1)
      {
          MessageBox.Show("You must select a column");
          return;
      }
      if (string.IsNullOrEmpty(tbSearch.Text))
      {
          MessageBox.Show("You must enter a value to search for");
          return;
      }

      // This bit would NOT normally be within the UI layer
      var conString = ConfigurationManager.ConnectionStrings["ConnectToDB"].ConnectionString;
      using (SqlConnection conn = new SqlConnection(conString))
      {
          conn.Open();
          using (var myCommand = new SqlCommand())
          {
              myCommand.Connection = conn;
              var sb = new StringBuilder(
                  "SELECT First_Name, Last_Name, Grid_Square, Country, State, Call_Sign, Date_Time, Mode, Power ");
              sb.Append("FROM clouddata WHERE ");
              sb.Append(cmbColumns.SelectedItem);
              sb.Append("=@searchValue");
              myCommand.CommandText = sb.ToString();
              myCommand.Parameters.AddWithValue("@searchValue", tbSearch.Text);

              using (var adapter = new SqlDataAdapter(myCommand))
              {
                  var myTable = new DataTable();
                  adapter.Fill(myTable);
                  dataGridView1.DataSource = myTable;
              }
          }
      }
  }

QuestionTeam Please help on the below request Pin
ganesh_naganna23-May-17 0:55
ganesh_naganna23-May-17 0:55 
AnswerRe: Team Please help on the below request Pin
Mycroft Holmes23-May-17 14:55
professionalMycroft Holmes23-May-17 14:55 
QuestionSQL for dynamic mappings Pin
Danpeking22-May-17 3:13
Danpeking22-May-17 3:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.