Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MySQL WindowsForms
Hi, I have a datagird and a textbox. Also I have member in MySql Database. So which is the code when I write a first letter of any member of database to show in datagird.
 
C# code is like that :
 _strQuery = "SELECT * FROM tblBibloteka WHERE Emri Like '%" + txtKerko.Text + "%'";
 
But I have problem with MySql...Some code with MySqlconnection and MySqlAdapter....
Can anyone help me?
 
--- Update from comments ---
Ok here we are.
I have a datagridview in my application(windows form)and I have a database with some members in mysql. In my windows form I also have a textbox. All what I need is code that when I write the character example 'L' in a textbox then in datagirdview to be listed all names with 'L'. So this textbox must be related with mysql .... I need a code for that.
Posted 13-Jun-12 6:32am
h5h5340
Edited 13-Jun-12 10:34am
Kschuler32.6K
v3
Comments
amitgajjar at 13-Jun-12 14:42pm
   
what problem with mysql ?
h5h5 at 13-Jun-12 16:21pm
   
problem is how to connect what I need. so when i write for ex. first letter of any name that is in mysql to show me in datagridview
Tim Corey at 13-Jun-12 14:53pm
   
It is unclear what you are asking for here. Can you please explain what you are attempting to do and where you are stuck?
h5h5 at 13-Jun-12 16:10pm
   
Ok here we are.
I have a datagridview in my application(windows form)and I have a database with some members in mysql. In my windows form I also have a textbox. All what I need is code that when I write the character example 'L' in a textbox then in datagirdview to be listed all names with 'L'. So this textbox must be related with mysql .... I need a code for that.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you are looking for just how to make the SQL statement work, you should try this:
_strQuery = "SELECT * FROM tblBibloteka WHERE Emri Like '" + txtKerko.Text + "%'";
 
The percent sign is a wildcard character, which means that if you are looking for data that STARTS with the letter, you want the wildcard to only appear AFTER that letter.
 
However, depending upon how your program works and how much data your database has, I'm guessing that it might function quicker and cleaner if you grab everything and instead of hitting the database each time you want to filter, you can just filter the data you already have. If you've connected your data to the DataGrid using a DataTable, you can just set the DataTable's .DefaultView.RowFilter property[^]
You can use the .RowFilter much like the WHERE portion of an SQL statement. For example you could set it to "Emri Like'" + txtKerko.Text + "%'"
 
And if you're actually wondering about how to connect to MySQL...you can check out http://www.connectionstrings.com/mysql[^] for info on what the connection string needs to be set to. You can also search on google[^] for articles on how to connect. Some of the ones listed there are even CodeProject articles.
 
Hope this helps.
  Permalink  
v2
Comments
h5h5 at 13-Jun-12 16:52pm
   
Maybe these can help you to help me, this is a code for sql, I need for mysql
private DataSet LexoShenimet(string _strQuery)
{
DataSet dsShenimet = new DataSet();
string _strKonektimiMeDB = "";
 
_strKonektimiMeDB = ConfigurationManager.ConnectionStrings["Aplikacion.Properties.Settings.dbBIBLOTEKAConnectionString1"].ConnectionString;

SqlConnection sqlKonektimi = new SqlConnection(_strKonektimiMeDB);
SqlDataAdapter sqlAdapteri = new SqlDataAdapter(_strQuery, _strKonektimiMeDB);
 
try
{
sqlKonektimi.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
sqlKonektimi.Close();
return null;
}
 
sqlAdapteri.Fill(dsShenimet);
sqlKonektimi.Close();
 
return dsShenimet;
}
h5h5 at 13-Jun-12 16:52pm
   
private void txtkerko_TextChanged(object sender, EventArgs e)
{
DataSet dsShenimet = new DataSet();
string _strQuery = "";
 
_strQuery = "SELECT * FROM tblBibloteka WHERE Emri Like '%" + txtKerko.Text + "%'";
dsShenimet = this.LexoShenimet(_strQuery);
dgvLista.DataSource = dsShenimet.Tables[0].DefaultView;
dgvLista.Columns["Mbiemri"].Visible = true;
}
Kschuler at 13-Jun-12 16:56pm
   
This is the kind of information that is much more helpful to put directly in the question where everyone who reads your question can see them and they will be formatted all nice and pretty. Click the Improve Question button and add this information to your question instead of here in a comment. Also, you should inform us of WHY that code isn't working. Are you getting an error message? If so, what is the exact wording of the error message?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,656
1 Sergey Alexandrovich Kryukov 6,490
2 CPallini 5,310
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web02 | 2.8.140921.1 | Last Updated 13 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100