TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
adnan
NA
4
4.2k
How to select data and display it in a DataGrid
Aug 6 2010 6:26 AM
Hi people, I'm new in this kind of programing and I have a problem whit my project.
I try to write the code for a action button (the find button that allow to find rows whit the specific parametrs), but i don't know how to write it in C# exactly.
In sql the code is SELECT * FROM atable WHERE ...... but how can I do it in C#
my code is:
private void btnTrazi_Click(object sender, EventArgs e)
{
try
{ string wanted="", wanted1, wanted2, wanted3, wanted4, wanted5;
//inicijalizacija varijabli po kojima se vrsi trazenje ali bez ikakvih ne dozvoljenih znakova
wanted1 = txtJMBG.Text.Trim();
wanted2 = txtIme.Text.Trim();
wanted3 = txtPrezime.Text.Trim();
wanted4 = txtPbrStan.Text.Trim();
wanted5 = txtBrTel.Text.Trim();
if (wanted1 != "")
{
katvDataSet1.korisnik.DefaultView.Sort = "JMBG";
int npoz = katvDataSet1.korisnik.DefaultView.Find(wanted1);
if (npoz == -1)
MessageBox.Show("Nepostoji zapis koji zadovoljava tražene parametre");
else
this.BindingContext[katvDataSet1, "korisnik"].Position = npoz;
}
else
{
if (wanted2 != "") wanted = "ime = " + wanted2;
if (wanted3 != "") wanted = wanted + " AND " + "prezime = " + wanted3;
if (wanted4 != "") wanted = wanted + " AND " + "pbrStan = " + wanted4;
if (wanted5 != "") wanted = wanted + " AND " + "telefon = " + wanted5;
Select *; from korisnik; where wanted; into dataGridView1;
}
}
catch
{
}
}
So if anyone can help me please do it :)
Reply
Answers (
2
)
stringbuilder example
To distroy a session variable