question on database query
-
hi.. the bottom code work very well.. but i have a few questions here.. for that code below.. 1) i did not declare any connectionstring 2) i did not call any sqlcommand query e.g. "select name from ..." is the way i do below good or bad? will it make things slow? because i did not specify the query "select name from.." .. , so the system will take time to take out all the data ?? instead of specify to my query? there are so many ways to do that .. e.g databinding to textbox.. so compared to this below?
void call_textbox() { DataTable store = new DataTable(); father.Fill(son.table); store = son.table; if (listBox1.SelectedIndex != -1) { //MessageBox.Show(store.Rows[listBox1.SelectedIndex].ItemArray[0].ToString()); foreach (DataRow row in store.Rows) { if (row[0].ToString() == store.Rows[listBox1.SelectedIndex].ItemArray[0].ToString()) { name.Text = row[1].ToString(); address.Text = row[2].ToString(); phone.Text = row[3].ToString(); } } } }
-
hi.. the bottom code work very well.. but i have a few questions here.. for that code below.. 1) i did not declare any connectionstring 2) i did not call any sqlcommand query e.g. "select name from ..." is the way i do below good or bad? will it make things slow? because i did not specify the query "select name from.." .. , so the system will take time to take out all the data ?? instead of specify to my query? there are so many ways to do that .. e.g databinding to textbox.. so compared to this below?
void call_textbox() { DataTable store = new DataTable(); father.Fill(son.table); store = son.table; if (listBox1.SelectedIndex != -1) { //MessageBox.Show(store.Rows[listBox1.SelectedIndex].ItemArray[0].ToString()); foreach (DataRow row in store.Rows) { if (row[0].ToString() == store.Rows[listBox1.SelectedIndex].ItemArray[0].ToString()) { name.Text = row[1].ToString(); address.Text = row[2].ToString(); phone.Text = row[3].ToString(); } } } }
are you want to select the record from the DataTable that the row index = listBox1.SelectedIndex???? if so, why not DataRow row = store.Rows[listBox1.SelectedIndex]; name.Text = row[1].ToString(); ... And there has a RowFilter properties in DataView(or DataTable.DefaultView), you can use it for filter any record you want... check it out in MSDN: http://msdn2.microsoft.com/en-us/library/system.data.dataview.rowfilter.aspx[^]
-
hi.. the bottom code work very well.. but i have a few questions here.. for that code below.. 1) i did not declare any connectionstring 2) i did not call any sqlcommand query e.g. "select name from ..." is the way i do below good or bad? will it make things slow? because i did not specify the query "select name from.." .. , so the system will take time to take out all the data ?? instead of specify to my query? there are so many ways to do that .. e.g databinding to textbox.. so compared to this below?
void call_textbox() { DataTable store = new DataTable(); father.Fill(son.table); store = son.table; if (listBox1.SelectedIndex != -1) { //MessageBox.Show(store.Rows[listBox1.SelectedIndex].ItemArray[0].ToString()); foreach (DataRow row in store.Rows) { if (row[0].ToString() == store.Rows[listBox1.SelectedIndex].ItemArray[0].ToString()) { name.Text = row[1].ToString(); address.Text = row[2].ToString(); phone.Text = row[3].ToString(); } } } }
thanks for reply.. anyway..my question is not on the listbox coding.. i have a few questions here.. for that code.. 1) i did not declare any connectionstring 2) i did not call any sqlcommand query e.g. "select name from ..." because if we specify the sqlcommand, will it save time to look for the data that we want instead of doing that in datatable like what i did above..?? why i did not declare the conntectionstring also can work? i did not declare the Using System.sqlclient.. which way is better ?
-
thanks for reply.. anyway..my question is not on the listbox coding.. i have a few questions here.. for that code.. 1) i did not declare any connectionstring 2) i did not call any sqlcommand query e.g. "select name from ..." because if we specify the sqlcommand, will it save time to look for the data that we want instead of doing that in datatable like what i did above..?? why i did not declare the conntectionstring also can work? i did not declare the Using System.sqlclient.. which way is better ?
- the connectionString has been stored in Properties.settings. 2) if you were drag and drop the datatable in to your program, SELECT, UPDATE, DELETE, INESRT Command will generate to you automatically... Depends on the usage in your program, if you will handle all sql command, it should be "faster". but if the record is not larger than 100,000. I don't think there has too much different. But development time ;P
-
- the connectionString has been stored in Properties.settings. 2) if you were drag and drop the datatable in to your program, SELECT, UPDATE, DELETE, INESRT Command will generate to you automatically... Depends on the usage in your program, if you will handle all sql command, it should be "faster". but if the record is not larger than 100,000. I don't think there has too much different. But development time ;P
-
i has also posted before to other forum.. what they said was the way i did will be slowing down eveyrthing..
-
Sorry for late reply. If you want to have a faster development time, you have to use the predefine or auto-gen code for your development, it will slow down the work, but it save in coding. But if you have time to design a better software structure, it will take time but faster in performance. It's depends on your choice.