|
Excuse me,
I have listbox binded sql datasource. & also
I have one two textboxes.
now I want to insert listbox items and these textbox values into sql table by one Submit click.
for example: the listbox contain 3 items.
ListBox:
Item 1
Item 2
Item 3
Textbox 1: text1
Textbox 2: text2
I want to insert these above values into sql table,
I also want to store priority value in sql table, as in the order of ListBox.
as follow:
When I clicked Submit button, data will be stored like below;
Sql Table1:
id | column1 | column2 | column3 | priority |
1 | text1 | text2 | item1 | 1 |
2 | text1 | text2 | item2 | 2 |
3 | text1 | text2 | item3 | 3 |
Next Time, when inserted new item values data...
Sql Table1
id | column1 | column2 | column3 | priority |
1 | text1 | text2 | item1 | 1 |
2 | text1 | text2 | item2 | 2 |
3 | text1 | text2 | item3 | 3 |
4 | text1 | text2 | item1 | 1 |
5 | text1 | text2 | item2 | 2 |
5 | text1 | text2 | item3 | 3 |
How I have to do?
I am using VS 2005 in C#. I am developing web project.
Thank in advance.
|
|
|
|
|
Its really simple. You have to put the insert code into a loop. From your description, suppose your list-box has 5 items. then you can make code like this
for(int i=0;i
|
|
|
|
|
Build datatable in code behind.Add all rows to the datatable. Then use sqlbulkcopy.It inserts all the records into database table in one shot.
SqlConnection destinationConnection = new SqlConnection(strConnection);
destinationConnection.Open();
SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection );
bulkCopy.DestinationTableName = "destination";
bulkCopy.WriteToServer(yourDatatable);
destinationConnection .Close();
Rams.Ch
|
|
|
|
|
Hi, I have applied for an entry-level job. I've been sent the following email and I have to program it before I can get an interview. I graduated in 2007 and have forgotten a lot, so have been teaching myself programming languages again recently.
Candidates are required to build an ASP.NET application, using C#.Net for code behind and targeting version 3.5 of the framework. The application will require a SQL server database for storage of data generated by the application. This application must perform the following tasks:
1. Allow the user to enter numbers, of any integer value and in random order. Sort these numbers in either ascending or descending order – the order should be chosen by the user.
2. The ordered sequence should be inserted into a database record along with the direction that the sequence was sorted in and the time taken to perform the sort.
3. Standard .Net controls should be used to bind to the newly inserted record and display the results of the ordering.
4. Again using standard .Net controls the results of all sorts should be available for display in either ascending or descending order of time taken and exportable as XML.
5. Use the design template provided to style your application.
6. Please document all assumptions and decisions taken separately and submit with final code base.
-------------------------
For 1: I have 6 text boxes the user will type numbers in to and a drop down list for them to select ascending or descending. When they click a button, all the numbers go into an array, it is sorted in the required order, and then the numbers will be output into the text boxes in the correct order - is this how you would do this?
I think I know how to add it to the database. The one part I'm stumped on is in part 2: How do I get the time taken to perform the sort? Do I use a Timer control? If so, how many decimal places would you use? 3 or 4? Or much more?
Thanks in advance for any help
modified 17-Dec-11 16:09pm.
|
|
|
|
|
I remember an array.reverse or something to sort
before sort, get the time stamp, when done get time stamp, and deduct the time using time difference.
That's a good test of skill.
|
|
|
|
|
Yep, for the sorting I used Array.Sort(myArray) for ascending. I did the same for descending with Array.Reverse(myArray) afterwards.
How do I do a timestamp? I've never worked with timers before in C# - only in VB and even then it was a very basic thing that counted up in seconds.
Could someone give me some code which times the sort and puts the amount of time into a float or double variable?
I've googled it and found QueryPerfCounter(). Is that what I need to use?
Thanks.
EDIT: I now have the following code:
var start = DateTime.now;
//code here which I am timing
int i = DateTime.Now.Subtract(start).Milliseconds;
TextBox1.Text = Convert.ToString(i);
The last line is just so I can test the answer I get. And I keep getting zero! I guess thats because I'm only measuring hours, minutes and seconds - not milliseconds. Can someone help?
modified 18-Dec-11 8:56am.
|
|
|
|
|
|
Thank you! I have now done it, using Stopwatch.
I had tried to use the stopwatch earlier and couldn't get it to work - all because I was missing the namespace using System.Diagnostics
|
|
|
|
|
I understand your desire to learn, however, I believe the intention of the interview process is to see what you can do, not what others recommend you do, or do for you. If you do manage to get to the next stage of the interview process, do you mention you had help with this? If you manage to get the job, will the employer expect you to deliver, or expect you to ask others?
It is one thing to research a problem; no one is expected to know everything. It is another matter entirely, IMO, to ask for help on such interview, or exam, questions.
Also keep in mind the there may be a good likelihood the person who gave you these questions checks sites like this for people asking questions like this.
No comment
|
|
|
|
|
hello,i have a question.I bulding a news page.I'm using C# asp.net.So,when i view a news related to Beckham.I want in the end of the news to show another news reated ti Beckham.
So,in my database,news column just have 4 column:title,content,summary,teaster image.
So,just in title have Beckham.how to display it in related news?
Example:From this title about David Beckham.The keyword "David" has choosen.And the related news in bottomto display the related news about "David".
http://www.newstrackindia.com/newsdetails/255070
Can you help me?Thank you.
|
|
|
|
|
It is simply a matter of forming the database query. Something like,
SELECT Title, Summary
WHERE Title CONTAINS('@keyword')
No comment
|
|
|
|
|
Hi,
I have an asp.net application which loads data from csv file. I need to check for duplicate rows in the csv file and should not process them and give error message for those duplicate rows.
I did in some approach but got the comments like performance is impacted. Is there any performance oriented process available to compare the string arrays
Any type of help is greatly appreciate.
Here is my code
private static bool CheckForDuplicateRow(FileInfo file
,string[] line
,int lineNumber
,ref bool lineAlreadyVerified)
{
CsvStream csvStream;
using (Stream fileStream = file.OpenRead())
{
using (StreamReader reader = new StreamReader(fileStream))
{
csvStream = new CsvStream(reader);
string[] rowItems;
try
{
csvStream.GetNextRow();
rowItems = csvStream.GetNextRow();
int rownumber = 1;
while (rowItems != null)
{
if ((rowItems.Length == line.Length) && (rownumber != lineNumber) && (rowItems.Length > 0))
{
bool b = AreRowItemsEqual(rowItems, line);
if (AreRowItemsEqual(rowItems, line) == true)
{
if (lineNumber < rownumber)
lineAlreadyVerified = true;
return true;
}
}
rowItems = csvStream.GetNextRow();
rownumber++;
}
}
catch (Exception e)
{
throw e;
}
}
}
return false;
}
private static bool AreRowItemsEqual(string[] rowItems, string[] line)
{
for (int i = 0; i < rowItems.Length; i++)
{
if (rowItems[i] != line[i])
{
return false;
}
}
return true;
}
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
modified 16-Dec-11 12:34pm.
|
|
|
|
|
indian143 wrote: I have an asp.net application which loads data from csv file. I need to check for duplicate rows in the csv file and should not process them and give error message for those duplicate rows.
Here's my approach:
ArrayList uniqueLines = new ArrayList();
ArrayList duplicateLines = new ArrayList();
String[] lines = File.ReadAllLines( "C:/file.csv" );
foreach ( String line in lines )
{
if ( !uniqueLines.Contains( line ) )
{
uniqueLines.Add( line );
}
else
{
duplicateLines.Add( line );
}
}
From the above, you have all the unique lines in the uniqueLines arraylist and you have duplicate lines in the duplicateLines arraylist.
To display errors, loop through the "duplicateLines" and tell the user about the error.
Happy Coding,
Morgs
|
|
|
|
|
Can I use List instead of ArrayList, because that class is not coming in my application, I dont know why?
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Yes, you can use List<string> if you want. The ArrayList comes from the: using System.Collections;
|
|
|
|
|
Hi,
Is there any way to get the which rows are repeated, like for example row 1, 3, 5 are same and 2 and 4 are same.
Is there any way to get that from this list?
thanks,
Abdul.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Hi,
For when click datalist item show pupup on parent window i use this code :
any other???????
protected void dlPhotos_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Select")
{
Response.Write("<script>");
Response.Write("window.open(Default3.aspx','_self','toolbar=0,location=0,menubar=0,resizable=0,width=400,height=320')");
Response.Write("</script>");
}
}
|
|
|
|
|
Jitendra Parida1987 wrote: ItemCommand(object source, DataListCommandEventArgs e)
this is server side code which will get executed the user clicks a button in your DataList. I am assuming that your expected behavior is not working.
since everything in your script appears to be static why not just write the script code into your .aspx page directly? add your control and on the click event call your javascript function. the only thing you need change is returning false so that it won't post back.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
Hi,
My requirement is dynamically implement so that i try this code.
|
|
|
|
|
Jitendra Parida1987 wrote: My requirement is dynamically implement
dynamically implement??
there is nothing dynamic about that script that you posted so why not just put it in a static javascript function that gets called from each item in the DataList. the html code that gets displayed is dynamically generated on the server so maybe that is it??
sounds like a homework assignment when you mention it this.. haha
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
hi,
please tell me what is problem in my code???????
|
|
|
|
|
Hi,
I have tried to deploy my web application (VS2010 + C#) by adding the project output and building a msi setup. But, I want to do these steps through command prompt. Our command scripts will do all the stpes to deploy in server.
That command prompt scripts should do the following things
1. Getting latest version of my solution
2. Adding web deployment project and adding project outputs there
3. Building and deploying in a server..
How to do that?
Thanks in advance.
Balasubramanian K.
|
|
|
|
|
hi
Request.ServerVariables("REMOTE_HOST") does not work on IIS 7. but work on IIS 5.1 and 7.5.
what problem can be?
|
|
|
|
|
i am looking for vertical according menu for asp.net shopping cart project.
the menu items accessed from database, please advice me how can i do that.
Thank you
NInad
|
|
|
|
|
There are javascript menu codes available
Please find the below link if its helpful for your query.
http://www.dynamicdrive.com/
Regards
Naina
Naina
|
|
|
|