473,385 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Edit Table

Hi

I am using a table to fill a dropdown box. The contents of the dropdown
box are ordered by a seq_no. I edit the seq_no and want to refresh the
dropdown box and show the new order. I can edit the table but the
changes to the seq_no is not changing the order of the dropdown box
when it is refreshed. Can anyone give me ideas on how to fix this?
Below is the code that I'm using.

//edit Question_Seq_No for record that is moved up
string sqlQuestionTempEditUP="UPDATE QuestionTemp SET Question_Seq_No =
'"+valSeqNum +"' " +
"WHERE Question_ID = "+valQuestionIDUp+" ";

SqlCommand sqlStatusCmdUP = new
SqlCommand(sqlQuestionTempEditUP,sqlConnection1);
sqlStatusCmdUP.CommandType = CommandType.Text;
daQuestionTemp.UpdateCommand =sqlStatusCmdUP;

sqlConnection1.Open();
rowcountUP=sqlStatusCmdUP.ExecuteNonQuery();
sqlConnection1.Close();

//Get the BTForm_Number
string sqlBTFormFind="SELECT * " +
"FROM BTForm " +
"WHERE BTForm_Status = 'Active' And ( BTForm_ID = "+valFormID+" )" ;

//sqlConnection1.Open();
SqlDataAdapter daBTFormFind=new SqlDataAdapter(sqlBTFormFind,
sqlConnection1);
dsMain1.BTForm.Clear();
daBTFormFind.Fill(dsMain1.BTForm);
DataTable dtBTForm = dsMain1.Tables["BTForm"];

DataRow BTFormRow;
BTFormRow = dtBTForm.Rows[0];

valBTFormNumberFind = (int)BTFormRow["BTForm_Number"];

drpQuestion.Items.Clear();

//Refresh the Question dropdown box
string sqlQuestionEdit="SELECT * " +
"FROM QuestionTemp " +
"WHERE (Question_Status = 'Active') And ( BTForm_Number =
"+valBTFormNumberFind+")" +
"Order By Question_Seq_No";

SqlDataAdapter daQuestionEdit=new SqlDataAdapter(sqlQuestionEdit,
sqlConnection1);
dsMain1.QuestionTemp.Clear();
daQuestionEdit.Fill(dsMain1.QuestionTemp);
DataTable questionDT = dsMain1.Tables["QuestionTemp"];

//fills the drpSelectQuestion
foreach (DataRow questionRow in questionDT.Rows)
{

ListItem newquestion= new ListItem();

newquestion.Text=questionRow["Question_Content"].ToString().Trim();
newquestion.Value=questionRow["Question_ID"].ToString().Trim();
drpQuestion.Items.Add(newquestion);
} //end foreach loop

Mar 9 '06 #1
1 1740
gjtired,

Instead of populating the items manually, why not bind to a DataView
where the sort order is set to the sequence number? Then, you can change
the order in the underlying data table, and it should update the list
automatically.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"gjtired" <jo****@boystown.org> wrote in message
news:11*********************@p10g2000cwp.googlegro ups.com...
Hi

I am using a table to fill a dropdown box. The contents of the dropdown
box are ordered by a seq_no. I edit the seq_no and want to refresh the
dropdown box and show the new order. I can edit the table but the
changes to the seq_no is not changing the order of the dropdown box
when it is refreshed. Can anyone give me ideas on how to fix this?
Below is the code that I'm using.

//edit Question_Seq_No for record that is moved up
string sqlQuestionTempEditUP="UPDATE QuestionTemp SET Question_Seq_No =
'"+valSeqNum +"' " +
"WHERE Question_ID = "+valQuestionIDUp+" ";

SqlCommand sqlStatusCmdUP = new
SqlCommand(sqlQuestionTempEditUP,sqlConnection1);
sqlStatusCmdUP.CommandType = CommandType.Text;
daQuestionTemp.UpdateCommand =sqlStatusCmdUP;

sqlConnection1.Open();
rowcountUP=sqlStatusCmdUP.ExecuteNonQuery();
sqlConnection1.Close();

//Get the BTForm_Number
string sqlBTFormFind="SELECT * " +
"FROM BTForm " +
"WHERE BTForm_Status = 'Active' And ( BTForm_ID = "+valFormID+" )" ;

//sqlConnection1.Open();
SqlDataAdapter daBTFormFind=new SqlDataAdapter(sqlBTFormFind,
sqlConnection1);
dsMain1.BTForm.Clear();
daBTFormFind.Fill(dsMain1.BTForm);
DataTable dtBTForm = dsMain1.Tables["BTForm"];

DataRow BTFormRow;
BTFormRow = dtBTForm.Rows[0];

valBTFormNumberFind = (int)BTFormRow["BTForm_Number"];

drpQuestion.Items.Clear();

//Refresh the Question dropdown box
string sqlQuestionEdit="SELECT * " +
"FROM QuestionTemp " +
"WHERE (Question_Status = 'Active') And ( BTForm_Number =
"+valBTFormNumberFind+")" +
"Order By Question_Seq_No";

SqlDataAdapter daQuestionEdit=new SqlDataAdapter(sqlQuestionEdit,
sqlConnection1);
dsMain1.QuestionTemp.Clear();
daQuestionEdit.Fill(dsMain1.QuestionTemp);
DataTable questionDT = dsMain1.Tables["QuestionTemp"];

//fills the drpSelectQuestion
foreach (DataRow questionRow in questionDT.Rows)
{

ListItem newquestion= new ListItem();

newquestion.Text=questionRow["Question_Content"].ToString().Trim();
newquestion.Value=questionRow["Question_ID"].ToString().Trim();
drpQuestion.Items.Add(newquestion);
} //end foreach loop

Mar 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Terry | last post by:
I need some help refining an MS 2000 relational databse. I have created a simple relational database using two tables, 'Student Details', 'Exam Details' and two forms, 'Input/Edit Exam Details',...
25
by: dixie | last post by:
I have some code that adds new records into a table for each ID in a list box when a button on a form is clicked. This works fine. My problem now is that I wish to be able to edit all the records...
0
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
7
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the...
9
bhcob1
by: bhcob1 | last post by:
Hey guys, 'Update or CancelUpdate without AddNew or Edit' On my database i keep occasionly get this error when i try and edit a field, it is not everytime. It will be working fine and then this...
2
by: sara | last post by:
I use Allen Browne's Audit Trail code in everything I do and I love it. Recently, I've run into a problem I can't figure out. I have a database with about 35 lookup tables. I am creating an...
1
by: ollielaroo | last post by:
Hi guys, Firstly I did do a search for this one first but I couldn't find anything related in this forum. I am using Dreamweaver MX and trying to build admin pages for an ASP site. My problem is...
0
by: DJOuk | last post by:
Posted this on Asp.Net, seems to be a hard problem, I still can't work it out I have a edit button, this works fine, until I add the code that prevents the edit button from being seen by users who...
1
by: chromis | last post by:
Hi, I'm having trouble fully implementing the edit section of a contact admin system, so far I have written the following: - Bean (Contact.cfc) - Data Access object (ContactDAO.cfc) - Gateway...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.