what can I do to my poorful combobox to be filled????
-
Hi guys, I develop a csharp smart device.I want know now fill my combobox with data extractedfrom my database .mdf(wishing that the TCP/IP goes well and the connection to my local server works well :laugh: ). My code is:
string sConnection = "Provider=SQLNCLI.1;Persist Security Info=False;User ID=sa;Initial Catalog=GMAO;Data Source=127.0.0.1,1433;Password=sa;";
string sSQL = "SELECT com FROM energie; ";
SqlConnection conn = new SqlConnection(sConnection);
SqlCommand comm = new SqlCommand(sSQL, conn);
DataSet ds = new DataSet();SqlDataAdapter da = new SqlDataAdapter(sSQL,conn); SqlDataReader dr = null; try { comm.Connection.Open(); da.Fill(ds, "SQL Temp Table"); foreach (DataRow d in ds.Tables\[0\].Rows) { MessageBox.Show("xxxx"); comboBox1.Items.Add(d.ItemArray\[0\].ToString()); } } catch (SqlException ex) { MessageBox.Show("connexion impossible"); MessageBox.Show(ex.Message); return; } dr.Close(); comm.Connection.Close();
Still not filled after running :( . what is the problem??? Thanks
-
Hi guys, I develop a csharp smart device.I want know now fill my combobox with data extractedfrom my database .mdf(wishing that the TCP/IP goes well and the connection to my local server works well :laugh: ). My code is:
string sConnection = "Provider=SQLNCLI.1;Persist Security Info=False;User ID=sa;Initial Catalog=GMAO;Data Source=127.0.0.1,1433;Password=sa;";
string sSQL = "SELECT com FROM energie; ";
SqlConnection conn = new SqlConnection(sConnection);
SqlCommand comm = new SqlCommand(sSQL, conn);
DataSet ds = new DataSet();SqlDataAdapter da = new SqlDataAdapter(sSQL,conn); SqlDataReader dr = null; try { comm.Connection.Open(); da.Fill(ds, "SQL Temp Table"); foreach (DataRow d in ds.Tables\[0\].Rows) { MessageBox.Show("xxxx"); comboBox1.Items.Add(d.ItemArray\[0\].ToString()); } } catch (SqlException ex) { MessageBox.Show("connexion impossible"); MessageBox.Show(ex.Message); return; } dr.Close(); comm.Connection.Close();
Still not filled after running :( . what is the problem??? Thanks
I suggest you run it under the debugger and see if a) there's a table in the dataset, and b) if there are rows in the table.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
I suggest you run it under the debugger and see if a) there's a table in the dataset, and b) if there are rows in the table.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001Hi, I really don't know to run it under the debugger???< Thanks
-
Hi, I really don't know to run it under the debugger???< Thanks
Put a breakpoint in the code at the point you want to break it. There's a shortcut to do this: press F9. Ensure you've built the code as a Debug build and press F5 to run it in debug mode. When your code hits the breakpoint, you can step over code using F10. To step into a function, press F11. To inspect the value of a variable, you can use the locals window, or the quick watch, you can inspect it with the immediate window or you can hover over the input in the running code and see the values in the visualizer. It's that easy, and you really need to learn how to debug your code - it's a vital skill.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Hi, I really don't know to run it under the debugger???< Thanks
It's almost impossible to help you until you learn how to use Visual Studio.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
Hi guys, I develop a csharp smart device.I want know now fill my combobox with data extractedfrom my database .mdf(wishing that the TCP/IP goes well and the connection to my local server works well :laugh: ). My code is:
string sConnection = "Provider=SQLNCLI.1;Persist Security Info=False;User ID=sa;Initial Catalog=GMAO;Data Source=127.0.0.1,1433;Password=sa;";
string sSQL = "SELECT com FROM energie; ";
SqlConnection conn = new SqlConnection(sConnection);
SqlCommand comm = new SqlCommand(sSQL, conn);
DataSet ds = new DataSet();SqlDataAdapter da = new SqlDataAdapter(sSQL,conn); SqlDataReader dr = null; try { comm.Connection.Open(); da.Fill(ds, "SQL Temp Table"); foreach (DataRow d in ds.Tables\[0\].Rows) { MessageBox.Show("xxxx"); comboBox1.Items.Add(d.ItemArray\[0\].ToString()); } } catch (SqlException ex) { MessageBox.Show("connexion impossible"); MessageBox.Show(ex.Message); return; } dr.Close(); comm.Connection.Close();
Still not filled after running :( . what is the problem??? Thanks
I suggest you read and study this article[^], even if you are using a different version of Visual Studio. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
It's almost impossible to help you until you learn how to use Visual Studio.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001Hi, It is not a problem if u don't like me to help me.There are always some starters in any field u know.The experimental ones try to help them.So,I am a starter :).If u try to help me,thank u a lot of u collaborativ caracter.Else,it is not time nor place to give me tips Thank u a lot :)
-
I suggest you read and study this article[^], even if you are using a different version of Visual Studio. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
Hi, I tried the breakpoint method.I see that the error in the filling of the databox(I verified my TCP/IP connection due to this thread http://www.codeproject.com/Messages/3470516/Re-How-can-check-the-result-of-the-TCP-IP-connecti.aspx[^]) What is the problem??? Thanks
-
Hi, It is not a problem if u don't like me to help me.There are always some starters in any field u know.The experimental ones try to help them.So,I am a starter :).If u try to help me,thank u a lot of u collaborativ caracter.Else,it is not time nor place to give me tips Thank u a lot :)
Hi "Starter", After reading your answer, I think I should give you a tip. ;P You seem to be a beginner in programming - otherwise you would know how to debug your code (with or without a debugger...) Many members on codeproject are real experts, ask them if you have a real problem. But before that, learn how to use your tools and language. No one likes the kind of "beginner" unwilling to learn and asking "questions". Developing for a smart device is even more challenging than for a PC platform - (I do it a lot) So if you still have the problem with your combobox and the problem is unspottable during debug - contact me - i will try to help you :rose: