Skip to content

Instantly share code, notes, and snippets.

Created May 2, 2016 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4fbf5fd1e91ebf336b4cebacad5e2ccc to your computer and use it in GitHub Desktop.
Save anonymous/4fbf5fd1e91ebf336b4cebacad5e2ccc to your computer and use it in GitHub Desktop.
private int SearchLog(Logbook searchParameters) // this is the search method.
{
try
{
int result;
string connection = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Databas.mdf;Integrated Security=True;Connect Timeout=30";
using (SqlConnection conn = new SqlConnection(connection))
{
conn.Open();
string sqlQuery = string.Format("Select name, title, text, date from lb WHERE {0} like @search", searchParameters.GetComboBox());
SqlDataAdapter sda = new SqlDataAdapter(sqlQuery, conn);
sda.SelectCommand.Parameters.AddWithValue("@search", "%" + searchParameters.GetSearchWord());
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
searchResult = dataGridView1.RowCount;
return searchResult;
}
}
// when creating a remove from database method. Should I use the return value into another query or what would be the best way?
DatabaseDataSet =
UL L U
lid(fk) lid(pk) uid(pk)
uid(fk) usr fn
pw ln
pid
But in database I have one more table LB (lbid, name, title, text, date)
Should I connect these or what? Because the LB table is not visible in DatabaseDataSet?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment