Showing posts with label selected. Show all posts
Showing posts with label selected. Show all posts

Saturday, March 31, 2012

Trim URL String

I am trying to populate selected values from a drop-down list into URL params. I have the below code, which is supposed to remove the trailing comma from the end of the URL, but it does not seem to be working. Does anyone see anything obviously incorrect?

Thanks in advance.
----------

if (lbxWFTemplate.Visible ==true)

{

strURL +="WFTemplate=";

foreach (ListItem liWFTemplatein lbxWFTemplate.Items)

{

if (liWFTemplate.Selected)

{

strURL += liWFTemplate.Value.ToString() +",";

}

}

strURL.TrimEnd(",".ToCharArray());

I actually figured this out right after I posted. Trimend() returns a string, so the following was changed, and the code works as expected now:
strURL = strURL.TrimEnd(",".ToCharArray());

Tuesday, March 13, 2012

Troubles with DropDownList

Hi

I've got problem with DropDownList, because when I change values, I've still got the first value of List.

So, how to set new selected value of DropDownList?I guess you have the following code concept in your page: "on a page_load, retrieve the data from a database or some other source and bind it to the control". This is right but incomplete. In fact Page_Load is fired also on a postback, so when a user selects something in the dropdownlist and the page is posted back (automatically or manually) to the server, the Page_Load is executed again. In order to execute the binding code only when needed, use this skeleton of code:

if (!Page.IsPostBack) {
//do the binding
}
//do other things that are not affected by a postback
.

Now, you're rebinding the controls every time the page is loaded; this code will perform the binding only when no postback is done (thus, only on the first request to the page).
Great Thanks
Now everything is working :)

Troubles with INSERT command

Hi, I am currently trying to INSERT selected rows from table Cart intotable Orders. Table Cart has columns Id_record(autonumber),Id_title(LongInt), Customer(text), Table Orders has the same columnsand also column Order_ID. When I delete this colums Order_ID and insertonly values from table cart like this, it works.
queryString = "INSERT INTO [Orders] SELECT * FROM [Cart] WHERE Cart.Customer = @dotnet.itags.org.user"
Dim dbCommand as OleDbCommand = new OleDbCommand(queryString, myConnection)
dbCommand.Parameters.Add(New OleDbParameter("@dotnet.itags.org.user", OleDbType.Char, 20))
dbCommand.Parameters("@dotnet.itags.org.user").Value = user.Identity.Name

Troubles begin, when I try to insert also that randomly generated number into my table Orders. I use this code...
Dim myConnection as OleDbConnection = new OleDbConnection(connectionString)
queryString = "INSERT INTO [Orders] SELECT *, @dotnet.itags.org.random as Order_ID FROM [Cart] WHERE Cart.Customer = @dotnet.itags.org.user"
Dim dbCommand as OleDbCommand = new OleDbCommand(queryString, myConnection)
dbCommand.Parameters.Add(New OleDbParameter("@dotnet.itags.org.user", OleDbType.Char, 20))
dbCommand.Parameters("@dotnet.itags.org.user").Value = user.Identity.Name
Randomize()
dbCommand.Parameters.Add(New OleDbParameter("@dotnet.itags.org.random", OleDbType.Integer, 20))
dbCommand.Parameters("@dotnet.itags.org.random").Value = ((Int32.MaxValue) * Rnd)
I always ger error "Duplicate output destination in Id_record" andhave no idea, how to fix it. Could pls somebody help me? Or could ugive me some link on some good INSERT tutorial?

If both the tables are not EXCTLY similar in columns you would get errors. So list out the column names xplicitly.
INSERT INTO col1, col2, col3 SELECT cart.col1, cart,col2, cart.col3 FROM cart WHERE Cart.Customer = @.user"

Exclude the identity column since you cannot manually insert into it.


Hm, so I changed my query into something like this, but now im gettingOverflow error. Does someone know what Overflow error means? Could bethis error caused bz the fact, that Id_record is autonumber in Carttable but I am trying to isnert it as integer in Orders table?

Dim myConnection as OleDbConnection = new OleDbConnection(connectionString)
queryString = "INSERT INTO [Orders] (Id_record,Id_title, Customer, Id_order) SELECT Id_record, Id_title, Customer,@.user FROM [Cart] WHERE Cart.Customer = @.user"
Dim dbCommand as OleDbCommand = new OleDbCommand(queryString, myConnection)
Randomize()
Dim Rand As Int32 = ((Int32.MaxValue) * Rnd)
dbCommand.Parameters.Add(New OleDbParameter("@.random", OleDbType.Integer, 20))
dbCommand.Parameters("@.random").Value = Rand
dbCommand.Parameters.Add(New OleDbParameter("@.user", OleDbType.Char, 20))
dbCommand.Parameters("@.user").Value = user.Identity.Name


queryString = "INSERT INTO [Orders] (Id_record, Id_title, Customer, Id_order) SELECT Id_record, Id_title, Customer, @.user FROM [Cart] WHERE Cart.Customer = @.user"

is Orders.Id_order column a autonumber column? if so you cant explicity insert into this column.
providing the sqldatatype(integer?) of Cart.Id_record is the same type as Orders.ID_record it shouldnt be a problem.
Well, Cart.ID_Record is the autonumber and Orders.ID_record is theinteger. I need to insert this autonumber into Orders.Id_record asinteger.
Orders.Id_order is normal Integer.
Edit: Hm, when i remove the last column from orders and try to insertjust first 3 columns, everything works fine. So the problem is either in the declaration of random variable or in the was it is placed in SQO query.


queryString = "INSERT INTO [Orders] (Id_record, Id_title, Customer, Id_order) SELECT Id_record, Id_title, Customer,@.user FROM [Cart] WHERE Cart.Customer = @.user"


whats with the @.user in the select list?
waht are you trying to do there with it?