This is how it worked in my program: String sEid = rdr["Eid"].ToString(); String sName = rdr["name"].ToString(); String sSurname = rdr["surname"].ToString(); String sAge = rdr["age"].ToString(); Eid_txt.Text = sEid; Name_txt.Text = sName; Surname_txt.Text = sSurname; Age_txt.Text = sAge; PS. Im using MsSql database
Got to say Tutorials 11 and 12.. Although not exactly what I was after, taken bits from it, and it was very helpful. One thing though, I've always been taught not to copy and paste code, strange to see someone actually doing it.
copy and pasting is fine for small snippets of code ...for speed - but you;re correct ....really a lot of the code in the example should have been placed in its own method and called where needed
he is working in MySQL database I'm in sql database if you the same this code will work for youstring sID = reader.GetString(reader.GetOrdinal("ID")); string sname = reader.GetString(reader.GetOrdinal("name")); string sSurname = reader.GetString(reader.GetOrdinal("surname")); string sAge = reader.GetString(reader.GetOrdinal("age"));that works for me
My problem is when I add or Save a new data (ex. new employee) it doesn't show in the combo box immediately , I have to rerun the system again for the combo box to show the new data. .please help how to show the new data immediately in the combo box?
Hy man! If you have THE SAME NAME in the database TWICE, the program will not work properly. Look at "mark" --> it's show just the last row with the eid=7. The row with eid=2 is not saved in the combox. Why? If anyone know how to fix this please leave a message! Thanks!
you do wrong query... look at 11:23 when you select first "mark" you should get eid=2 , but you get eid=7. column name is not unique so when you select name from edata where name="mark" you get 2 record and while loop use last record ...
Sir, I want my second comboBox show data according to the data selected in First comboBox. example, In ComboBox1, i want to select the gender like (male or female), and according to comboBox1 selection , the comboBox2 show the name of only Male (if selected) or only Female (if selected )
i made listbox2 and i had to put where name= '"+ comboBox1.SelectedItem +"' by the way i am using a different table to get the combobox value when i click on another item in combobox it doesnt change the vallue in the listbox2 it stays the same value
Its really time wasting task to follow these examples, while they are very good to learn from. I dont understand the idea why the developer just dont leave the code written? To save us from following them for hours? and saving us from small mistakes? I spent hours making this example, and I got " unable to connect to any of the specified mysql hosts" So, please next time when you do something, do it complete. and leave the code to download it
This is how it worked in my program:
String sEid = rdr["Eid"].ToString();
String sName = rdr["name"].ToString();
String sSurname = rdr["surname"].ToString();
String sAge = rdr["age"].ToString();
Eid_txt.Text = sEid;
Name_txt.Text = sName;
Surname_txt.Text = sSurname;
Age_txt.Text = sAge;
PS. Im using MsSql database
hello mam mssql only support int value so you should give your colum number instead of colum name
thanks
Hi,
The code that I have shared in my previous post, worked as it was for me...
Hope it helps you too.
Pinar U.S. Thanx this comment helped me a lot...........
+Pinar U.S. you are great you really solve a complex problem in this tutorial thank for this
assign index no instead of names
Got to say Tutorials 11 and 12.. Although not exactly what I was after, taken bits from it, and it was very helpful.
One thing though, I've always been taught not to copy and paste code, strange to see someone actually doing it.
copy and pasting is fine for small snippets of code ...for speed - but you;re correct ....really a lot of the code in the example should have been placed in its own method and called where needed
he is working in MySQL database I'm in sql database if you the same this code will work for youstring sID = reader.GetString(reader.GetOrdinal("ID"));
string sname = reader.GetString(reader.GetOrdinal("name"));
string sSurname = reader.GetString(reader.GetOrdinal("surname"));
string sAge = reader.GetString(reader.GetOrdinal("age"));that works for me
Love you. Video is hard to follow, but what i needed was this, exactly.
Thanks a lot bro... that was a great help
thanks your tutorials are helpfull eventhough i am programming in vb net the libraries are the same
You are a beast my brother, thank you for saving my butt in the project.
How the hell did you pass a string into GetString() when it requires an int variable?
excelente video tutorial me servira en mi proyecto de residencia muy buen aporte .
saludoss.. me gustan tus videos (Y)..
All your tutorials were very helpful. Thank you for all your videos :)
Corrected:
1)
void Fillcombo()
{
string constring = "server=localhost; user=root;database=mydb;DefaultTableCacheAge=30;charset=utf8";
string Query = "select * from mydb.towary ;";
MySqlConnection conDatabase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand(Query, conDatabase);
MySqlDataReader myReader;
try
{
conDatabase.Open();
myReader = cmdDataBase.ExecuteReader();
comboTowary.Items.Clear();
//MessageBox.Show("Deleted");
while (myReader.Read())
{
string ID = myReader.GetString("idTowary");
string sName = myReader.GetString("nazwaTowaru");
comboTowary.Items.Add(ID + "_"+ sName);
}
2)
private void comboTowary_SelectedIndexChanged(object sender, EventArgs e)
{
string constring = "server=localhost; user=root;database=mydb;DefaultTableCacheAge=30;charset=utf8";
string Query = "select * from mydb.towary WHERE CONCAT_WS('_',idTowary,nazwaTowaru)='"+ comboTowary.Text + "';";
Dude you're awesome, thanks for all this tutorials
Hi Brother there is a worst case that which id will we get if there are two same names?
Is it posible to use only one connection? Why do you have to create a new one each time??? Tnks four your help.
Excellent tuto..Many thanks
Can we type a name in combobox rather than selecting it? It will be helpful in cases where you have many names to scroll and select!
yes i agree - that's called autocomplete where matching entries appear as you type each letter of the search term
Very Helpful. Thank You
can i do this with a text box instead? where when he types a id no. all values show in the textbox
I have 3 buttons in a form in c# which goes to the same page but how do I get the names of respective buttons saved in the sql server?
My problem is when I add or Save a new data (ex. new employee) it doesn't show in the combo box immediately , I have to rerun the system again for the combo box to show the new data. .please help how to show the new data immediately in the combo box?
at the time 9:23 why we are not assigning directly to the textboxs instead of strings or int what ever .... as there any benefit please answer.
Very nice 👍
What about WPF comboboxes.. The SelectedIndexChange doesn't exist and the SelectedValue changes after the code behind has run.
how to do the reverse process, sir. I want to control the data of combo box in case some data is inserted into a textbox. please help
my COBOL professor said to me that you will never write a program, you will tailor an existing program to fit your needs.
Hy man! If you have THE SAME NAME in the database TWICE, the program will not work properly.
Look at "mark" --> it's show just the last row with the eid=7. The row with eid=2 is not saved in the combox.
Why? If anyone know how to fix this please leave a message! Thanks!
Nice job!
you do wrong query... look at 11:23 when you select first "mark" you should get eid=2 , but you get eid=7. column name is not unique so when you select name from edata where name="mark" you get 2 record and while loop use last record ...
I am using MSSQL.In MSSQL I have used ToString in place of varchar,what should I use for Int type?please help
cannot convert from 'string' to 'int' ???? plz help
You need Typecasting Like - parseInt();
Does anyone else expererince that nothing happens? nothing is shown in the combobox?
+Daniel Santelices just add .SelectedItem on the combobox you used in the query
How to perform same operation in ASP.NET MVC 4 Razor ???
Please let me know if somebody knows ?
Please tell me how to display date database to textbox when select combobox..
Sir,
I want my second comboBox show data according to the data selected in First comboBox.
example,
In ComboBox1, i want to select the gender like (male or female),
and according to comboBox1 selection , the comboBox2 show the name of only Male (if selected) or only Female (if selected )
plz help me.. I stuck on it in my project.
rdr.GetString("Breed").ToString(); error
i made listbox2 and i had to put where name= '"+ comboBox1.SelectedItem +"'
by the way i am using a different table to get the combobox value
when i click on another item in combobox it doesnt change the vallue in the listbox2 it stays the same value
Thank very much!
What if there are exactly two names in the database?
thanx bro.....
Super
if there is one radio button then how to do ???????
Error cannot convert from 'string' to 'int' how can i handle it? please help
int itemId = myReader.GetInt32(myReader.GetOrdinal("ItemId"));
thanx bro
how to perform same operation in android studio? please help anyone
Love You Man...!
how to do in webpages
You have error, mark its 2, and allways is id=7
thank dude
do this in java please
kindly share the source code its imp for beginers
you heard the kid !! - yes please share the code
ta ch zhe chenakr psmam :D
Code doesn't work, bud
quality sucks AND WHY DO YOU RECORD ONLY YOUR MOUSE WHY NOT THE WHOLE SCREEN ITS SO HARD TO WATCH
Its really time wasting task to follow these examples, while they are very good to learn from. I dont understand the idea why the developer just dont leave the code written? To save us from following them for hours? and saving us from small mistakes?
I spent hours making this example, and I got "
unable to connect to any of the specified mysql hosts"
So, please next time when you do something, do it complete. and leave the code to download it
Thank you!