Get &> Array &> Split &> Listbox
Hi everyone,
having some problems
Basically, using ASP.NET 2.0 and here is my problem,
Get data from table
Put into array
Split where there is a +
remove +'s
assign to listbox to give a list of everything in that table
The + split the courses, so in my Order table I have A + B + C etc and I want all of the different options in a list box (note different records have different entries it isn't always a b c)
I am testing my code, here is what I got
Public Sub TitleChange(ByVal Sender As Object, ByVal E As EventArgs)
Try
Dim DBConn As SqlConnection
Dim DSPageData As DataSet = New DataSet()
Dim VarTxtAOE As String
DBConn = New SqlConnection("Server=SD02;Initial Catalog=WhoGetsWhat;Persist Security Info=True;UID=x;Password=XXX")
'Dim DBDataAdapter As SqlDataAdapter
DBDataAdapter = New SqlDataAdapter("Select AOE FROM TBL_Role WHERE Title = @ddlTitle", DBConn)
DBDataAdapter.SelectCommand.Parameters.Add("@ddlTitle", SqlDbType.NVarChar)
DBDataAdapter.SelectCommand.Parameters("@ddlTitle").Value = TitleDropDown.SelectedValue
DBDataAdapter.Fill(DSPageData, "Courses")
'Need to find out what this rows business is about whats the number about? and am I doing it correct?
'txtAOE.Text = DSPageData.Tables("Courses").Rows(0).Item("AOE")
'txtAOE.Items.Add(New ListItem(DSPageData.Tables(0).Rows(0).Item("AOE")))
VarTxtAOE = DSPageData.Tables("Courses").Rows(0).Item("AOE")
Dim VarArray() As String = VarTxtAOE.Split("+")
Response.Write(VarArray())
txtAOE.DataSource = VarArray()
txtAOE.DataBind()
'Response.Write(test)
'ListBox1.DataSource = test
'Response.Write(VarArray)
Catch TheException As Exception
lblerror.Text = "Error occurred: " & TheException.ToString()
End Try
End Sub
My response.Write works correctly, but my list box doesn't, also I don't want to say which bit of the array like I have done using 1, I just want to display the whole array in my list box. I am not worrying about removing the +'s at the minute, just splitting my data and putting each section into a listbox
Maybe I am going about this the wrong way, but I have been trying a lot of different things and its hard to find any help
Thanks
Chris
View Complete Forum Thread with Replies
Related Forum Messages:
Split Array
hi, how can i split text separated by semicolumn in different cells: text1;text2;text3; into 1 - text1 2 - text2 3 - text3 thank you
View Replies !
How Would I Send A String Array As A Integer Array?
I have a stored procedure that has a paramter that accepts a string of values. At the user interface, I use a StringBuilder to concatenate the values (2,4,34,35,etc.) I would send these value to the stored procedure. The problem is that the stored procedure doesn't allow it to be query with the parameter because the Fieldname, "Officer_UID" is an integer data type, which can't be query against parameter string type. What would I need to do to convert it to an Integer array? @OfficerIDs as varchar(200) Select Officer_UID From Officers Where Officer_UID in (@OfficerIDs) Thanks
View Replies !
Array Of Array - IRR Function
Hi, I am using the IRR function in a report. I have created the following code so it creates an array: Public GroupIRRArray(-1) As Double Public Function addToIRRArray(ByVal BMV As Decimal, ByVal BAB As Decimal, ByVal EMV As Decimal, ByVal EAB As Decimal, ByVal CFB As Decimal) Dim g As Integer g = uBound(GroupIRRArray) + 1 ReDim Preserve GroupIRRArray(g) if g=0 then GroupIRRArray(g) = (CFB+EAB-BAB+BMV)*-1 else if g=1 then GroupIRRArray(g) = (BAB-CFB-EAB+EMV) else GroupIRRArray(g-1)= GroupIRRArray(g-1)-(BMV) GroupIRRArray(g) = (BAB-CFB-EAB+EMV) end if End Function It works fine but now I want to create multiple groups within my report. How can I change the code so it loops on another parameter? What I had in mind was to create an initial array with the parameter value that I want to use for grouping and a dynamic array based on the name of each group. So I would end up with one array containing the group name plus x number of arrays with the raw data. Alternatively, is there a way to use the IRR function without creating a custom code? Like a conversion parameter that would make my floating field a one dimensional array? Thanks, Jam
View Replies !
Several Listbox's With A SP
I am wandering how to "Properly do this" Without doing a dynamic SP. How do I do a search with the multiple listbox data. What do I pass the stored procedure? SELECT ID, LAST_NAME || ', ' || FIRST_NAME AS FULLNAMEFROM BIT_USER1WHERE (TYPE_ID = 1) OR (TYPE_ID = 3) OR (TYPE_ID = 4) OR (TYPE_ID = 5) OR (BLDG_ID = 1) OR (BLDG_ID = 2)ORDER BY LAST_NAME, FIRST_NAME
View Replies !
How Do I Populate A Listbox From A SQL DB?
Sorry if this is to basic but I am just starting out. Any help is appreciated. Basically I am attempting to populate a listbox with items from a MSSQL DB so the user can select either one or multiple items in that listbox to search on.
View Replies !
Listbox Selected Values
Hi. With VWD i've produced the following code.<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:50469ConnectionString %>"SelectCommand="SELECT * FROM [ibs] WHERE ([liedID] = @liedID)"><SelectParameters><asp:ControlParameter ControlID="ListBox1" Name="liedID" PropertyName="SelectedValue" Type="Int16" />But the query is only returning one row of the table. Even when multiple values were selected in the ListBox1. Could someone tell me how to do?Thanks, Kin Wei.
View Replies !
Best Way To Use Listbox Selection In WHERE ... IN (...) Clause?
I need to use the list of items from a multiselect listbox in a parameter of a query's IN clause. Example: I assemble the list from the listbox and set the paramter value so @CityList = 'London','Paris','Rome' .... etc. A sample SQL would be: SELECT * FROM Customers WHERE City IN (@CityList) However, the SQL will not work. It seems the whole string is put in another set of single quotes by the compiler so it's treated as one string literal instead of a list. Is there a way around this?
View Replies !
Removing Duplicate In Listbox
Hi There, I am having a 1st listbox which is populating production lines, 2nd combobox to populate the production units. From here , the user will be able to select multiple production units from the combobox and hence populate the variable in listbox 3. This is the query that I'm using to query on the variable table: 'SELECT DISTINCT PU_Id,Var_Id,Var_Desc from Variables where PU_Id IN (@ProductionUnits)' The problem now is that this would return all the variables for the selected production units and for those variables that have the same name, they would appear in the listbox as duplicates. I wonder if there's any way to filter off or remove the duplicates in the listbox 3 by using sql query? Thanks in advance for the help. ksyong17
View Replies !
Automaticallyselecting Only Value In Listbox Field
Hello, I am new to SQL and I am populating a listbox with a sql statement that returns two values. These values will change from user to user, but will never change for that one user. I have populated the two fields in the Form_open command, but in order for them to become a value they need to be clicked on by the user. I want to bypass that part. Can anyone point me in the right direction? I have included what I have done. Thanks! Private Sub Form_Open(Cancel As Integer) Dim clockID As String Dim EmployeeId As Integer Dim db As Database Dim rs As Recordset Dim sql As String Set db = CurrentDb clockID = GetOpSysUser sql = "SELECT EMP_ID FROM EMPLOYEES WHERE CLOCK_ID = '" & clockID & " '" Set rs = db.OpenRecordset(sql) EmployeeId = rs.Fields(0) Name_Combo.RowSource = "SELECT EMP_ID, EMP_NAME FROM EMPLOYEES WHERE CLOCK_ID = '" & clockID & "'" company_text.RowSource = "SELECT COMPANY_NAME FROM COMPANY, EMPLOYEES WHERE COMPANY.COMPANY_ID = EMPLOYEES.COMPANY_ID AND CLOCK_ID = '" & clockID & "'" 'Me.Hours_text.Value = " " rs.Close End Sub
View Replies !
Selected Listbox Values In SQL Statement
I have seen some information on this but have not understood fully the answers. I am fairly new to this and have spent the afternoon trying to work on this and although I have leant some really cool things I am no nearer. How do I get selected values from a LIstbox into a SQL statement using the IN command First I loop through a List box control to get the multi selected values: Dim li As ListItemFor Each li In lbPClass.Items If li.Selected = True Then strPC += li.Value & ", " End IfNextLabel5.Text = strPC The result in the lable looks something like: 100, 101, 102 , I get rid of the trailing blank and commar with:Label6.Text = Left(Label5.Text, Trim(Len(Label5.Text) - 2)) I have created a parameter called @PROPCLASS that will use the values from the selected values in the listbox in a SQL query using an IN statement: Cmd.Parameters.Add(New OleDbParameter("@PROPCLASS", Label6.Text)) strSQL = "SELECT * FROM web_transfer WHERE ( PROP_CLASS IN (@PROPCLASS)) AND (ACRES >= @lowSize)AND (ACRES < @HighSize) AND (YEAR = @lowYear)AND (SALE_PRICE > @lowPrice) AND (SALE_PRICE < @highPrice) " It is really the first bit of the WHERE clause I am interested in. The sql statement works if I either type in the actual values IN( 100, 101,102) or if I select only one value in the list box. If I select two then the sql statement does not work. My question is: How do I get the values selected in the List box into my SQL statement Thank you in advance, s
View Replies !
ListBox Mutli-Select Through A For Each Loop
Hi everyone, not sure if a this topic has been covered yet (a have been looking all day), but as I am still very new to this, my problem is as follows: In the Try .. Catch block below, data is posted from a form and the SqlCommand.ExecuteScalar() statement returns a Unique Job ID. I am attempting to populate a subordinate table for qualifications which are selected from a ListBox, but rather than using qualification titles, I am using the values. My problem is that only one value (the first) gets posted multiple times, when multiple values are selected. Looking at the For Each loop in the inner Try Catch block, I am wondering whether there is some sort of Index pointer that needs to be incremented, in order to establish new values further down the list. I have seen no evidence that this is the case, save for the fact that the value stalls on just the first. Any help would be appreciated. ===== CODE === Try C4LConnection.Open() JobPostingID = SqlJobPost.ExecuteScalar()Response.Write("<br />Selected Item: " & Qualifications.SelectedItem.Value) Try ' Multiple Qualification EntriesSqlQualPost.Parameters.Add(New SqlParameter("@JobPostingID", SqlDbType.Int)) SqlQualPost.Parameters("@JobPostingID").Value = Int32.Parse(JobPostingID)SqlQualPost.Parameters.Add(New SqlParameter("@QualificationID", SqlDbType.Int)) SqlQualPost.Parameters("@QualificationID").Value = Int32.Parse(Qualifications.SelectedItem.Value) If Qualifications.SelectedIndex > -1 ThenFor Each Item In Qualifications.Items If Item.Selected ThenResponse.Write("<br />SelectedItem Value: " & Qualifications.SelectedItem.Text) QualPostingID = SqlQualPost.ExecuteScalar()SqlQualPost.Parameters("@QualificationID").Value = Int32.Parse(Qualifications.SelectedItem.Value) Response.Write("<br />Selected Item: " & Qualifications.SelectedItem.Value) End If Next End IfCatch Exp As SqlException failJobPost = True lblError.Visible = TruelblError.Text = "Could not add qualifications <br />" & Exp.Message End Try failJobPost = FalseCatch Exp As SqlException failJobPost = True lblError.Visible = TruelblError.Text = "Error: could not post job to database <br />" & Exp.Message Finally C4LConnection.Close() End Try
View Replies !
Use Listbox Values To Do Select Statement
Hi, I have SQL database 2000 which has one table Sheet1, I retrieved the columns in the ListBox, then chosed some of them and moved it to ListBox2. The past scenario worked great, and I checked the moved values, it was succesfully moved, but when I tried to copy the values in ArrayList to do a select statement it didn't worked at all. public string str;protected void Button3_Click(object sender, EventArgs e) {ArrayList itemsSelected = new ArrayList(); string sep = ","; //string str;for (int i = 0; i < ListBox2.Items.Count; i++) {if (ListBox2.Items[i].Selected) { itemsSelected.Add(ListBox2.Items[i].Value); } int itemsSelCount = itemsSelected.Count; // integer variable which holds the count of the selected items. str = ListBox2.Items[i].Value + sep; Response.Write(str); } SqlConnection SqlCon = new SqlConnection("Data Source=AJ-166DCCD87;Initial Catalog=stat_rpt;Integrated Security=True;Pooling=False"); String SQL1 = "SELECT " + str + " from Sheet1"; SqlDataAdapter Adptr = new SqlDataAdapter(SQL1, SqlCon); SqlCommandBuilder CB = new SqlCommandBuilder(Adptr);DataTable Dt = new DataTable(); Adptr.Fill(Dt); //return Dt; GridView1.DataBind(); SqlCon.Close(); } I did some changes and the new error message is Incorrect syntax near the keyword 'from'. Thank you
View Replies !
Selected Listbox Items Into Database
How can i get ALL the selected items into the database? this loop only accepts one item. I have tried with a "clear" action, does not work.... protected void Button2_Click(object sender, EventArgs e) { if (Page.IsValid) { // Define data objects SqlConnection conn; SqlCommand comm; // Open the connection string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; // Initialize connection conn = new SqlConnection(connectionString); // Create command comm = new SqlCommand("INSERT INTO TestTabel (TestNavn) VALUES (@TestNavn)",conn); // Add command parameters foreach (ListItem item in TestListBox.Items) { if (item.Selected) { comm.Parameters.Add("@TestNavn", System.Data.SqlDbType.NVarChar); comm.Parameters["@TestNavn"].Value = Item.Text; } } // Enclose database code in Try-Catch-Finally try { // Open the connection conn.Open(); // Execute the command comm.ExecuteNonQuery(); // Reload page if the query executed successfully Response.Redirect("Default.aspx"); } catch(Exception Arg) { Response.Write(Arg.Message); // Display error message Label1.Text = "Error !"; } finally { // Close the connection conn.Close(); } } }
View Replies !
Grabbing A Value From Listbox To Query Database
hello forum, I need to grab a string value from a list box in from a web form, and pass it to a sql select command statement where that value is equal toall values in a database table(sql 2000). example zip code list box3315433254 845788547535454 selected value is 85475 I am putting that value in a string like this: dim string_zip as stringstring_zip = zip_ListBox.text Question, how do i pass that value to sql stament, i am using this but does not work. SqlCommand1 = New SqlCommand("SELECT zip FROM table WHERE zip = string_zip", SqlConnection1)
View Replies !
How To Insert All The Values From A Listbox Into The Database?
I want that the user can chose several options from one ‘listbox’, and to do this, I have created two ‘listbox’, in the first one there are the options to select, and the second one is empty. Then, in order to select the options I want the user have select one or more options from the first ‘listbox’ and then click in a link to pass the options selected to the second ‘listbox’. Thus, the valid options selected will be the text and values in the second ‘listbox’. I have seen this system in some websites, and I think it is very clear. Well, my question is, Is it possible to insert into the database all the values from a ‘listbox’ control? In my case from the second ‘listbox’ with all the values passed from the first one? If yes, in my database table I have to create one column (field) for every possible selected option? Thank you, Cesar
View Replies !
Recordset Error While Filling The Listbox
Hello all I have shifted my vb/access database to vb/mysql and i have one form in my project in which i want to display all the records in the database in the list box . But while doing this i m getting the error " variable uses an automation type not supported in visual basic " . Moreover, it was working in Vb/access . here is the code Dim sql As String intCountSW_ID = 0 sql = "select SW_IDEN, SW_NAME, SW_DELETE,SW_LEFTDATE from SV_SOCIALWORKER order by SW_NAME" If rs.State = 1 Then rs.Close Set connString = New ADODB.Connection connString.CursorLocation = adUseClient connString.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _ & "SERVER=;" _ & "DATABASE=shrivatsa;" _ & "UID=root;" _ & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384 connString.Open rs.ActiveConnection = connString rs.CursorLocation = adUseClient rs.Open sql, connString, adOpenStatic, adLockOptimistic intCountSW_ID = rs.RecordCount If intCountSW_ID > 0 Then rs.MoveFirst While Not rs.EOF /* here comes the error on the below code If rs("SW_DELETE") = 0 And IsNull(rs("SW_LEFTDATE")) */ Then lstCaseName.AddItem rs("SW_IDEN") & " " & rs("SW_NAME") End If rs.MoveNext Wend rs.Close End If mfuncFillList = intCountSW_ID
View Replies !
Can Get Listbox To Load Data From Database
I have a sql server database linked to my application. I have a table that I want one of the columns (Service Perfomed) to load in a list box. When I start the application nothing appears in the list box. What could I be doing wrong? Here the code the visual studio created: Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load Me.ServiceTableAdapter.Fill(Me.MaintenanceRecordsDataSet.Service) End Sub I've tried combo box, text box and these seem to work fine but not the list box.
View Replies !
ListBox Web Server Control And Stored Procedure
Hi, I've a ListBox Web Server Control where I select a list of citiesnow I would like to create a stored procedure with the selected values... please note that I use metods like these for execute my Stored procedure public DataSet Getgfdfgh(SqlConnection connection, String IDAttivitaTipo, DateTime DataInizio, DateTime DataFine) { ConnectionState currState = connection.State; if (((connection.State & ConnectionState.Open) != ConnectionState.Open)) connection.Open(); try { SqlParameter[] parameters = new SqlParameter[3]; parameters[0] = new SqlParameter("@IDAttivitaTipo", IDAttivitaTipo); parameters[1] = new SqlParameter("@DataInizio", DataInizio); parameters[2] = new SqlParameter("@DataFine", DataFine); SqlCommand cmd = CreateStoreProcedureCommand("Getfhdfh", connection, parameters); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapter.Fill(ds); return ds; } finally { if ((currState == ConnectionState.Closed)) connection.Close(); } } How Can I manage a list of values ??Thanks for help me!!
View Replies !
How To Save Listbox Multiple Select Values
Hi, I have an ASP.NET form that stores it's data in MSDE but I just added a multi-select ListBox to the form and I'm having a hard time coming up with a way of writing that data to the database. Should I write the values into a column on the same table where I store the rest of the data from the form (values separated by a comma) or shouild I create another table (one to many) and store the data there. I like the second option, but I'm not sure how to loop through each value and write it to the database table. I grab the values for the selection as follow: foreach (ListItem lstItem in lbAttendees.Items) { if (lstItem.Selected == true) { grpList.Add(lstItem.Value.ToString()); } } but I'm not sure on what to do next and could use some help. Thanks Germano
View Replies !
How Do I Store Multiple Selected Listbox Items
Hi There This is probably realy simple but since im still a newbie some help would be appreciated. I have a listbox bound to an sqldatasource which has names of people from my sql database employeeDetails table. I simply want to allow someone to select to select multiple names and insert them into another field in my database. I have this bit workng, ie they can select multiple people on the list, it does insert, however only the first selected name, not the others.Can you please help me out Kind Regads Dan
View Replies !
Multiple Selection Listbox As Data Control?
Hi, i have a listbox with multiple selection enabled, the end user uses this listbox to select what data they want to view eg. they select "green" to view all the green cars, "red" to select all the red cars etc. i have the listbox as the control that is connected to the datasource (the sql used for it is select * from cars_table where color =@colorthis works fine when one item in the listbox is selected, but when multiples are selected it does not work what format does the =@color have to be when multiples are selected? i've tried "green, red" "green + red" etc. but cannot seem to get it workingdoes anybody have any working examples that i can take a look at? it seems to be a common action, yet i cannot seem to find any documentation on how to get it to workthanks in advance!
View Replies !
Sending Multiple Values From A ListBox To ControlParameter
Any ideas on how I can send multiple values from a listbox to a stored procedure? right now I have a ListBox Control called lbCategory, and I want to pass multiple selected items to a stored procedure. <asp:SqlDataSource ID="dsFS" runat="server" ConnectionString="someConnectionString" SelectCommand="usp_FS" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:ControlParameter ControlID="lbCategory" DefaultValue="%" Name="category" PropertyName="SelectedValue" type="String" /> </SelectParameters> </asp:SqlDataSource>
View Replies !
Query Database User Input From ListBox
I have a problem selecting fields from a table where fields are equal to user input from a listbox. example listbox of zip codes: 33023[red]22300[/red]39844[red]29339[/red]23883[red]38228[/red] user wants to retreive highlight zip codes from database.connection working perfect.Thank you for your help.
View Replies !
Using Asp.net Listbox Control (multiple Selection) And Sproc
I have a form where a user can select multiple items from a listbox control.How can I pass each item selected to a sproc? Do i need to created a paramter for each item in my listbox in my sproc?Has anyone done this, I dont want to create dynamic sql to handle this and i dont really want to create 100 parameters to handle my listbox items.thanks
View Replies !
Creating SQL Statements Programmatically From Listbox (ADVANCED)
I am creating a page that creates a report based on a dynamically created SQL statement which is created by user input. Everything is good except for the WHERE section, which is created from values in a list box. For Example: lstCriteria.items(1).value = "COMPANY = 'foo'" lstCriteria.items(2).value = "DAY= 2" I build my SQL statement with these values like so: SELECT * FROM POO WHERE COMPANY = 'foo' AND DAY = 2 The problem I am having is when there are multiple values of the same type in the list box. Say: lstCriteria.items(1).value = "COMPANY = 'foo'" lstCriteria.items(2).value = "DAY= 2" lstCriteria.items(1).value = "COMPANY = 'moo'" My employer wants this to be valid, but I am having a tough time coming up with a solution. I know that my SQL statement needs to now read: SELECT * FROM POO WHERE COMPANY = 'foo' AND DAY = 2 OR COMPANY = 'poo' AND DAY = 2 I have code set up to read the values of each list box item up to the "=". And I know that I need to compair this value with the others in the list box...but I am not running into any good solutions. Any HELP?
View Replies !
How To Loop Through This Sql Table And Display In Ms Access Listbox
I have a table in SQL, that I know how to connect to using ADO, but Ineed help on how to read records from that table.So on a form I have a listbox where I want to populate that and i havea textbox with a userid.Here is an example of the table:USER ID TYPE PAYMENT=====================0001 CARD 150.000001 CASH 250.000002 CASH 175.00If I have 0001 in the txtuserid textbox, I then want to display inthe listbox:CARD 150.00CASH 250.00How would I do this?thanks
View Replies !
Why Wont This Multiple Selection Listbox Insert Values Into Db
Hi, im a newbie. using VB.net / visual studio 2005 and SQL express I have pasted my page code below Basically i have a lisbox which is bound to an sqldatasource. It allows the user to select multiple names. I then have another datasource which when the page is submitted it posts various values from different fields into my db. The insert works fine.My problem is that the multiple selection wont allow me to insert into my db, it just captures the first value.I used this sub below to prove that when i click a button on my page it takes all my selected choices and puts them inside a text box, this works i can see them all. I then bound the textbox text value to the one im inserting into the db, however once again its only inserting the first value from the text box, how is this possible, the text box shows all the values and its set to string, it should insert everything in the text box Protected Sub selectedContact_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim alternatives As ListBox = CType(UploadPictureUI.FindControl("alternatives"), ListBox) Dim TextBox1 As TextBox = CType(UploadPictureUI.FindControl("TextBox1"), TextBox) For intLoopIndex As Integer = 0 To alternatives.Items.Count - 1 If alternatives.Items(intLoopIndex).Selected Then TextBox1.Text &= alternatives.Items(intLoopIndex).Text & _ ControlChars.CrLf End If Next End Sub Here is my full page code 1 <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Create Profile" Debug="true" %> 2 <script runat="server"> 3 Protected Sub UploadPictureUI_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles UploadPictureUI.ItemInserting 4 'Reference the FileUpload control 5 Dim UploadedFile As FileUpload = CType(UploadPictureUI.FindControl("UploadedFile"), FileUpload) 6 7 'Make sure a file has been successfully uploaded 8 If UploadedFile.PostedFile Is Nothing OrElse String.IsNullOrEmpty(UploadedFile.PostedFile.FileName) OrElse UploadedFile.PostedFile.InputStream Is Nothing Then 9 ShowErrorMessage("No file was uploaded. Please make sure that you've selected a file to upload.") 10 e.Cancel = True 11 Exit Sub 12 End If 13 14 'Make sure we are dealing with a JPG or GIF file 15 Dim extension As String = Path.GetExtension(UploadedFile.PostedFile.FileName).ToLower() 16 Dim MIMEType As String = Nothing 17 18 Select Case extension 19 Case ".gif" 20 MIMEType = "image/gif" 21 Case ".jpg", ".jpeg", ".jpe" 22 MIMEType = "image/jpeg" 23 Case ".png" 24 MIMEType = "image/png" 25 26 Case Else 27 'Invalid file type uploaded 28 ShowErrorMessage("Only GIF, JPG, and PNG files can be uploaded.") 29 e.Cancel = True 30 Exit Sub 31 End Select 32 33 'Specify the values for the MIMEType and ImageData parameters 34 e.Values("MIMEType") = MIMEType 35 36 'Load FileUpload's InputStream into Byte array 37 Dim imageBytes(UploadedFile.PostedFile.InputStream.Length) As Byte 38 UploadedFile.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length) 39 e.Values("imageData") = imageBytes 40 End Sub 41 42 Private Sub ShowErrorMessage(ByVal msg As String) 43 ErrorMessage.Text = msg 44 ErrorMessage.Visible = True 45 End Sub 46 47 Protected Sub UploadPictureUI_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles UploadPictureUI.ItemInserted 48 'If item successfully inserted, send user back to default 49 If e.Exception Is Nothing Then 50 Response.Redirect("~/confirmation.aspx") 51 End If 52 End Sub 53 54 Protected Sub selectedContact_Click(ByVal sender As Object, ByVal e As System.EventArgs) 55 Dim alternatives As ListBox = CType(UploadPictureUI.FindControl("alternatives"), ListBox) 56 Dim TextBox1 As TextBox = CType(UploadPictureUI.FindControl("TextBox1"), TextBox) 57 For intLoopIndex As Integer = 0 To alternatives.Items.Count - 1 58 If alternatives.Items(intLoopIndex).Selected Then 59 TextBox1.Text &= alternatives.Items(intLoopIndex).Text & _ 60 ControlChars.CrLf 61 End If 62 Next 63 End Sub 64 65 66 </script> 67 <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 68 <table border="0" cellpadding="0" cellspacing="0" style="vertical-align: middle; 69 width: 795px; text-align: center"> 70 <tr> 71 <td align="center" style="height: 650px" valign="middle"> 72 <asp:DetailsView ID="UploadPictureUI" runat="server" AutoGenerateRows="False" CssClass="createProfile" 73 DataKeyNames="id" DataSourceID="accessProfiles" GridLines="None" DefaultMode="Insert"> 74 <Fields> 75 <asp:TemplateField HeaderText="Create Profile"> 76 <InsertItemTemplate> 77 <table style="width: 350px"> 78 <tr> 79 <td align="center" style="width: 150px; height: 30px"> 80 Name:</td> 81 <td align="center" style="width: 200px; height: 30px"> 82 <asp:TextBox ID="Nametxtbx" runat="server" CssClass="textboxstyle" Text='<%# Bind("Name") %>' MaxLength="20"></asp:TextBox> 83 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Nametxtbx" 84 CssClass="errorMessage" ErrorMessage="First Name is Required" ForeColor="">*</asp:RequiredFieldValidator></td> 85 </tr> 86 <tr> 87 <td align="center" style="width: 150px; height: 30px"> 88 Email:</td> 89 <td align="center" style="width: 200px; height: 30px"> 90 <asp:TextBox ID="emailtxtbx" runat="server" CssClass="textboxstyle" Text='<%# Bind("email") %>'></asp:TextBox> 91 <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="emailtxtbx" 92 CssClass="errorMessage" ErrorMessage="Email Address is Required" ForeColor="">*</asp:RequiredFieldValidator> 93 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="emailtxtbx" 94 ErrorMessage="RegularExpressionValidator" ForeColor="" ValidationExpression="w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*">*</asp:RegularExpressionValidator></td> 95 </tr> 96 <tr> 97 <td align="center" style="width: 150px; height: 30px"> 98 Mobile:</td> 99 <td align="center" style="width: 200px; height: 30px"> 100 <asp:TextBox ID="mobiletxtbx" runat="server" CssClass="textboxstyle" Text='<%# Bind("mobile") %>' MaxLength="11"></asp:TextBox> 101 <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="mobiletxtbx" 102 CssClass="errorMessage" ErrorMessage="Mobile Number is Required" ForeColor="">*</asp:RequiredFieldValidator> 103 </td> 104 </tr> 105 <tr> 106 <td align="center" style="width: 150px; height: 30px"> 107 Extension:</td> 108 <td align="center" style="width: 200px; height: 30px"> 109 <asp:TextBox ID="extensiontxtbox" runat="server" CssClass="textboxstyle" Text='<%# Bind("extension") %>' MaxLength="11"></asp:TextBox> 110 <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="extensiontxtbox" 111 CssClass="errorMessage" ErrorMessage="Phone Extension is Required" ForeColor="">*</asp:RequiredFieldValidator></td> 112 </tr> 113 <tr> 114 <td align="center" style="width: 150px; height: 30px"> 115 Alternative Contact:</td> 116 <td align="center" style="width: 200px; height: 30px"> 117 <asp:ListBox ID="alternatives" runat="server" CssClass="listboxstyle" 118 DataSourceID="getAlternatives" DataTextField="Name" DataValueField="Name" SelectedValue='<%# Bind("alternativeContact") %>' 119 SelectionMode="Multiple"></asp:ListBox> 120 <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="alternatives" 121 CssClass="errorMessage" ErrorMessage="Alternative Contact is Required" ForeColor="">*</asp:RequiredFieldValidator></td> 122 </tr> 123 <tr> 124 <td align="center" style="width: 150px; height: 30px"> 125 Job Role:</td> 126 <td align="center" style="width: 200px; height: 30px"> 127 <asp:DropDownList ID="DropDownList2" runat="server" CssClass="dropdownliststyle" DataSourceID="accessrole" 128 DataTextField="role" DataValueField="roleID" AppendDataBoundItems="True" SelectedValue='<%# Bind("roleID") %>'> 129 <asp:ListItem Value="" Selected="False">- Please Select -</asp:ListItem> 130 </asp:DropDownList> 131 <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="DropDownList1" 132 CssClass="errorMessage" ErrorMessage="Job Role is Required" ForeColor="">*</asp:RequiredFieldValidator></td> 133 </tr> 134 <tr> 135 <td align="center" style="width: 150px; height: 30px"> 136 Responsibilities:</td> 137 <td align="center" style="width: 200px; height: 30px"> 138 <asp:TextBox ID="resposibilities" runat="server" CssClass="textareastyle" Text='<%# Bind("responsibilities") %>' 139 TextMode="MultiLine" MaxLength="200"></asp:TextBox> 140 <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="resposibilities" 141 CssClass="errorMessage" ErrorMessage="Role Responsibilities are Required" ForeColor="">*</asp:RequiredFieldValidator></td> 142 </tr> 143 <tr> 144 <td align="center" style="width: 150px; height: 29px"> 145 Hobbies:</td> 146 <td align="center" style="width: 200px; height: 29px"> 147 <asp:TextBox ID="hobbiestxtbx" runat="server" CssClass="textareastyle" Text='<%# Bind("hobbies") %>' 148 TextMode="MultiLine" MaxLength="200"></asp:TextBox></td> 149 </tr> 150 <tr> 151 <td align="center" style="width: 150px; height: 30px"> 152 Team Name:</td> 153 <td align="center" style="width: 200px; height: 30px"> 154 <asp:DropDownList ID="DropDownList1" runat="server" CssClass="dropdownliststyle" DataSourceID="accessTeam" 155 DataTextField="TeamName" DataValueField="TeamID" AppendDataBoundItems="True" SelectedValue='<%# Bind("TeamID") %>'> 156 <asp:ListItem Value="" Selected="False">- Please Select -</asp:ListItem> 157 </asp:DropDownList> 158 <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="DropDownList2" 159 CssClass="errorMessage" ErrorMessage="Team Name is Required" ForeColor="">*</asp:RequiredFieldValidator></td> 160 </tr> 161 <tr> 162 <td align="center" style="width: 150px; height: 30px"> 163 I am a Manager:</td> 164 <td align="center" style="width: 200px; height: 30px"> 165 <asp:CheckBox ID="isManager" runat="server" Checked='<%# Bind("isManager") %>' Text="Yes" /></td> 166 </tr> 167 <tr> 168 <td align="center" style="width: 150px; height: 30px"> 169 I am a Team Manager:</td> 170 <td align="center" style="width: 200px; height: 30px"><asp:CheckBox ID="isTeamManager" runat="server" Checked='<%# Bind("isTeamManager") %>' Text="Yes" /></td> 171 </tr> 172 <tr> 173 <td align="center" style="width: 150px; height: 30px"> 174 MyManager is:</td> 175 <td align="center" style="width: 200px; height: 30px"> 176 <asp:DropDownList ID="myManagerIs" runat="server" CssClass="dropdownliststyle" DataSourceID="MyManager" 177 DataTextField="Name" DataValueField="id" AppendDataBoundItems="true" SelectedValue='<%# Bind("teamManagerID") %>'> 178 <asp:ListItem Value="" Selected="False">- Please Select -</asp:ListItem> 179 </asp:DropDownList> 180 </td> 181 </tr> 182 <tr> 183 <td align="center" style="width: 150px; height: 30px"> 184 Upload Image:</td> 185 <td align="center" style="width: 200px; height: 30px"> 186 <asp:FileUpload ID="UploadedFile" runat="server" 187 Width="150px" /> </td> 188 </tr> 189 <tr> 190 <td align="center" style="width: 150px; height: 30px"> 191 Image Title:</td> 192 <td align="center" style="width: 200px; height: 30px"> 193 <asp:TextBox ID="imagetitle" runat="server" CssClass="textboxstyle" Text='<%# Bind("imageTitle") %>' MaxLength="30"></asp:TextBox> 194 <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="imagetitle" 195 CssClass="errorMessage" ErrorMessage="Image Title is Required" ForeColor="">*</asp:RequiredFieldValidator></td> 196 </tr> 197 <tr> 198 <td align="center" style="width: 150px; height: 30px"> 199 Hide This Profile:</td> 200 <td align="center" style="width: 200px; height: 30px"> 201 <asp:CheckBox ID="profileHide" runat="server" Checked='<%# Bind("Display") %>' /></td> 202 </tr> 203 <tr> 204 <td align="center" colspan="2" style="height: 30px"> 205 <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("alternativeContact") %>'></asp:TextBox><br /> 206 <asp:LinkButton ID="selectedContact" runat="server" OnClick="selectedContact_Click" OnClientClick="selectedContact_Click">Add Selected Contacts</asp:LinkButton></td> 207 </tr> 208 <tr> 209 <td align="center" colspan="2" style="height: 30px"> 210 <asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="errorMsgstyle" 211 ForeColor="" /> 212 </td> 213 </tr> 214 </table> 215 </InsertItemTemplate> 216 <HeaderTemplate> 217 218 </HeaderTemplate> 219 </asp:TemplateField> 220 <asp:TemplateField ShowHeader="False"> 221 <EditItemTemplate> 222 223 </EditItemTemplate> 224 <InsertItemTemplate> 225 <asp:LinkButton ID="btnInsert" runat="server" CausesValidation="True" CommandName="Insert" 226 Text="Insert"></asp:LinkButton> 227 <asp:LinkButton ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel" 228 Text="Cancel"></asp:LinkButton> 229 </InsertItemTemplate> 230 <ItemTemplate> 231 232 </ItemTemplate> 233 </asp:TemplateField> 234 </Fields> 235 </asp:DetailsView> 236 <br /> 237 <asp:Label ID="ErrorMessage" runat="server" CssClass="errortext"></asp:Label> <br /> 238 239 </td> 240 </tr> 241 <tr> 242 <td style="width: 100px"> 243 <asp:SqlDataSource ID="accessProfiles" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 244 InsertCommand="INSERT INTO [employeeDetails] ([isManager], [isTeamManager], [Name], [RoleID], , [extension], [mobile], [alternativeContact], [imageTitle], [imageMimeType], [imageData], [TeamID], [Display], [teamManagerID], [responsibilities], [hobbies]) VALUES (@isManager, @isTeamManager, @Name, @RoleID, @email, @extension, @mobile, @alternativeContact, @imageTitle, @MimeType, @imageData, @TeamID, @Display, @teamManagerID, @responsibilities, @hobbies)" > 245 <InsertParameters> 246 <asp:Parameter Name="isManager" Type="byte" DefaultValue="0" Size="1" /> 247 <asp:Parameter Name="isTeamManager" DefaultValue="0" Size="1" Type="Byte" /> 248 <asp:Parameter Name="Name" Type="String" /> 249 <asp:Parameter Name="RoleID" Type="Int32" /> 250 <asp:Parameter Name="email" Type="String" /> 251 <asp:Parameter Name="extension" Type="String" /> 252 <asp:Parameter Name="mobile" Type="String" /> 253 <asp:Parameter Name="alternativeContact" Type="String" /> 254 <asp:Parameter Name="imageTitle" Type="String" /> 255 <asp:Parameter Name="MimeType" Type="String" /> 256 <asp:Parameter Name="imageData" /> 257 <asp:Parameter Name="TeamID" Type="Int32" /> 258 <asp:Parameter Name="Display" type="Byte" DefaultValue="1" Size="0" /> 259 <asp:Parameter Name="teamManagerID" Type="Int32" /> 260 <asp:Parameter Name="responsibilities" Type="String" /> 261 <asp:Parameter Name="hobbies" Type="String" /> 262 </InsertParameters> 263 </asp:SqlDataSource> 264 <asp:SqlDataSource ID="accessrole" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 265 SelectCommand="SELECT [role], [RoleID] FROM [role] ORDER BY [role] DESC"></asp:SqlDataSource> 266 <asp:SqlDataSource ID="MyManager" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 267 SelectCommand="SELECT id, Name, isManager, isTeamManager FROM employeeDetails WHERE (isManager > 0) OR (isTeamManager > 0) ORDER BY Name DESC"> 268 </asp:SqlDataSource> 269 <asp:SqlDataSource ID="accessTeam" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 270 SelectCommand="SELECT [TeamID], [TeamName] FROM [Team] ORDER BY [TeamName] ASC"></asp:SqlDataSource> 271 <asp:SqlDataSource ID="getAlternatives" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 272 SelectCommand="SELECT [Name] FROM [employeeDetails] ORDER BY [Name]"></asp:SqlDataSource> 273 </td> 274 </tr> 275 </table> 276 </asp:Content> 277 278 Thanks for your help
View Replies !
Passing Multiple Values From A Listbox Into A Stored Procedure
hi i have a listbox with selectedmode = multiple, i am currently using this code in my code behind (c#) to call the storedprocedure within the datasource but its not working: Do i have to write specific code in c# to send the mulitple values through?protected void confButton_Click(object sender, EventArgs e) { try {foreach (ListItem item in authorsListBox4.Items) {if (item.Selected) { AddConfSqlDataSource.Insert(); } }saveStatusLabel.Text = "Save Successfull: The above publication has been saved"; }catch (Exception ex) {saveStatusLabel.Text = "Save Failed: The above publication failed to save" + ex.Message; } }
View Replies !
Listbox Contents To Sql Stored Procedure Command Parameter?
Hello, Stuck in a spot and hoping someone will nudge me in the right direction.... I'm trying to write to a sql db via a storedprocedure using a parameter. i'm pretty certain the below statement is causing the problem. but i'm not sure how to properly refer to it.... Dim connString As String connString = "integrated security=false;user id=sa;server=HCENT1;database=LicenseRenewal;persist security info=False" Dim myConnection As New SqlConnection(connString) Dim myCommand As New SqlCommand("InsertPage1", myConnection) myCommand.CommandType = CommandType.StoredProcedure ' .......other (working) parameter statements......... Dim parameterDates As New SqlParameter("@Dates", SqlDbType.VarChar, 4000) parameterDates.Value = Session("lstDates") myCommand.Parameters.Add(parameterDates) myConnection.Open() myCommand.ExecuteNonQuery() myConnection.Close() the session("lstDates") is the contents of lstDates.Items (listbox) from a previous page. i'm guessing its not valid to refer to it as a varchar, can someone point me to the proper way to handle this? tia andy
View Replies !
Can I Set Each Item In A Listbox As A Parameter When Updating Access Database?
Hello everyone. I am using C#, and posted this in the C# forum, but was told to try here, as for some reason I just can't get this to work. Everyone was very helpful, but for some reason I keep getting a message that a value is not being given for one or more required parameters. This doesn't make any sense though, as I am specifying a value for all parameters... Basically, I have a listBox that has several items in it. I want to update the database for each item that appears in the listBox. I can't seem to get this to work though, no matter what I try, and it is driving me nuts... lol Here is a link to my original thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2349891&SiteID=1 Here is my code: Code Block string whereClause = ""; for (int i = 0; i < Panel1ListView1.Items.Count; i++) { if (i == 0) { whereClause = "ID = " + Panel1ListView1.Items[0].Text; } else { whereClause += " OR ID = " + Panel1ListView1.Items[i].Text; } } try { using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Environment.CurrentDirectory + @"DB.mdb;Jet OLEDB:Database Password=xxx;")) { OleDbCommand cmd; conn.Open(); string command = "UPDATE [Table1] SET [Status] = @P1, [Name] = @P2, [Number] = @P3 WHERE " + whereClause; cmd = new OleDbCommand(command, conn); cmd.Parameters.Add("@P1", OleDbType.VarChar).Value = Panel1TextBox3.Text; cmd.Parameters.Add("@P2", OleDbType.VarChar).Value = Panel1TextBox1.Text; cmd.Parameters.Add("@P3", OleDbType.VarChar).Value = Panel1TextBox2.Text; int i = cmd.ExecuteNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } I really appreciate any help anyone can give me. I REALLY want to get this working. I am open to any suggestions and will try anything. Thank you very much for your help.
View Replies !
Sorting Parameter Listbox On Analysis Services Datasource
Hi all, How must I change the mdx that is generated for the available values for a user parameter in order to get the content sorted? Regards, Henk BTW the exact mdx query is given below (and the label field of the parameter is set to 'ParameterCaption'), but I would already appreciate an example of a simple mdx. MEMBER [Measures].[ParameterCaption] AS '[Organisatie].[Level 5 naam].CURRENTMEMBER.MEMBER_CAPTION' MEMBER [Measures].[Nummer en Naam] AS '[Organisatie].[Kosten Nummer].CURRENTMEMBER.MEMBER_CAPTION +": "+ [Organisatie].[Level 5 naam].CURRENTMEMBER.MEMBER_CAPTION' --MEMBER [Measures].[ParameterValue] AS '[Organisatie].[Level 5 naam].CURRENTMEMBER.UNIQUENAME' MEMBER [Measures].[ParameterLevel] AS '[Organisatie].[Level 5 naam].CURRENTMEMBER.LEVEL.ORDINAL' SELECT {[Measures].[ParameterCaption], [Measures].[Nummer en Naam] , [Measures].[ParameterValue], [Measures].[ParameterLevel]} ON COLUMNS , filter ([Organisatie].[Level 5 naam].MEMBERS,[Measures]) ON 1 , [Organisatie].[Kosten Nummer] on 2 FROM ( SELECT ( STRTOSET(@OrganisatieLevelnaam, CONSTRAINED) ) ON COLUMNS FROM ( SELECT ( STRTOSET(@KalenderFactuurPeriode, CONSTRAINED) ) ON COLUMNS FROM ( SELECT ( STRTOSET(@KalenderFactuurJaarNummerLang, CONSTRAINED) ) ON COLUMNS FROM [FMR DWH Afgenomen Dienst])))
View Replies !
SQLCeconnection On Visual Basic And Insert Data On A Listbox
Hi I am developing a program on Visual Basic 2005 to a pocket pc, I want to make the SQLceconnection but It says that the file doesn´t exists, I use this code: Dim conn As New SqlCeConnection() Dim Recordset As SqlCeDataAdapter Dim SQL As String Dim ds As New DataSet conn.ConnectionString = _ "Data Source = '.BDDclimatologicos.sdf';" conn.Open() SQL = "select [Provincia] from ZonasClimaticas" Recordset = New SqlCeDataAdapter(SQL, conn) Recordset.Fill(ds, "ZonasClimaticas") lstboxProvincias.DataSource = ds.Tables("ZonasClimaticas").DefaultView I have Dcilmatologicos.sdf on a folder named BD next to the folder of the executable, I don´t know what happends. My database has one table "ZonasClimaticas" and a column named "Provincia" on that, my other question is: Is this the right code to show that column on a listbox? Thank you very much!
View Replies !
SqlDataSource - Filter By Selection From Listbox - WHERE ([Name] IN ('Alaska','alabama'))&"
I have a listbox and SqlDataSource. I am not sure how to take the multiple value that are selected in listbox and use it to generate a sqlquery.Below I have shown that if I hard code it in the Command statement it works but I not sure how to take it from a variable or the listbox. ---------------------------------------------------------- <asp:ListBox ID="ListBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Name" SelectionMode="Multiple" Width="341px"></asp:ListBox> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT classifieds_Ads.Id, classifieds_Ads.MemberId, classifieds_Ads.CategoryId, classifieds_Ads.Title, classifieds_Ads.Description, classifieds_Categories.Name, classifieds_Ads.Price, classifieds_Ads.Location, classifieds_Ads.ExpirationDate, classifieds_Ads.DateCreated FROM classifieds_Ads INNER JOIN classifieds_Categories ON classifieds_Ads.CategoryId = classifieds_Categories.Id WHERE ([Name] IN ('ALASKA','alabama'))"> <SelectParameters> <asp:ControlParameter Name="Name" ControlID="listbox1" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource> --------------------------------------------------------
View Replies !
Array
I messed up my question so badly a few posts ago, that I'm going to lay out the problem carefully as follows: On a spreadsheet: --there are a few names down column A, one name per row (e.g., r3c1Mary, r4c1Scott, r5c1Jane, r6c1Ann, r7c1Cathy, r8c1Jim) --there are a bunch of columnar animals heading up row 1 (e.g., r1c2cat, r1c4dog, r1c6horse, r1c8bird, r1c10snake, r1c12elephant, r1c14goat, r1c16giraffe, r1c18ox, r1c20rat, r1c22monkey, r1c24pig) --(might be addressed in a later post to this or another thread): on row 2, there is a Budget field and a Cost field for each animal (e.g., r2c2Bud, r2c3Cost, r2c4Bud, r2c5Cost, r2c6Bud, r2c7Cost, r2c8Bud, r2c9Cost, r2c10Bud, r2c11Cost, r2c12Bud, r2c13Cost, r2c14Bud, r2c15Cost, r2c16Bud, r2c17Cost, r2c18Bud, r2c19Cost, r2c20Bud, r2c21Cost, r2c22Bud, r2c23Cost, r2c24Bud, r2c25Cost) But for now, just the people names down the left side, and the animals across the top would suffice to pose my question. The question is this: the number of animal types gets added to, or subtracted from, across the top of the page every month. On July, there might be 12 animal kinds listed; but on August, there might be 19--or there might be 11. (The number of people involved change as well.) As a user, I don't know how many and of what kind of animals (aka fields) will be on the page on any given month. The underlying query to the table doesn't know whether a Giraffe is going to be a category, among others at the top of the sheet, from one month to the next. If a garden variety query was written, it would hard code: SELECT r1c2cat, r1c4dog, r1c6horse, r1c8bird, r1c10snake, r1c12elephant, r1c14goat, r1c16giraffe, r1c18ox, r1c20rat, r1c22monkey, r1c24pig. But that rots. The query would have to be re-written for every new list of applicable animals each month. Or even more ugly, I'd have a predetermined number of variables to hold each type of animal; some would go unused while a number exceeding the variables available wouldn't make it into the query, or whatever. I could on the other hand slowly loop through a SELECT sAnimalType for each sPerson. Slowly. That's where my question comes in: Can a query be written that allocates a SELECT Array(sAnimalType)? (And if so, I hope I can extract the sequential info accordingly.) Simplified, I currently have an Access table with two columns (four if we go whole hog): Person, Animal (, Budget, Cost). (But I'm perfectly happy to leave Budget and Cost for a separate posting. Maybe that's a sub query or something.) Thanks for any assistance that you can provide.
View Replies !
Parameterized Or Array With This SQL?
I have two CheckBoxList controls. One CheckBoxList is a group of area codes as they apply to our customers, and the second CheckBoxList is a group of categories of those customers. The code below works fine with either CheckBoxList as a standalone (this code applies to the Area Codes selection), but what I need is the VB code to combine the choices a user makes in both CheckBoxLists. Is this where parameterized SQL comes into play? Or can I/should I use an array statement to combine both CheckBoxList choices? Sometimes a user will select nothing in one CBL and a few choices in the other, or vice versa, or a handful of choices in both CBLs, so that they might want only customers in, say two area codes and then only the selected categories of those area codes. Need help on this one, thanks...Protected Sub btn_CustomerSearchCombine_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_CustomerSearchCombine.Click Dim ACSelections As Boolean = False Dim ACItem As ListItem For Each ACItem In cbl_CustomerSearchAREA.Items If ACItem.Selected Then ACSelections = True End If Next If ACSelections = True Then Dim ACSqlString As String ACSqlString = "SELECT Customers.CustomerID, Customers.CustomerName, Customers.CategoryID, Customers.EstHours, Customers.Locality, Categories.Category FROM Customers INNER JOIN Categories ON Customers.CategoryID = Categories.CategoryID WHERE " For Each ACItem In cbl_CustomerSearchAREA.Items If ACItem.Selected Then ACSqlString &= "Customers.AreaCodeID = '" & ACItem.Value & "' OR " End If Next ACSqlString = Left(ACSqlString, Len(ACSqlString) - 4) ACSqlString &= "ORDER By Customers.CustomerName" sql_CustomerSearchGrid.SelectCommand = ACSqlString End IfEnd Sub
View Replies !
DataRow Array
Hi, i m pretty new to this forum and c#.net i m doin a project in c#.net I have four values in my datarow array for example DataRow[] cmb; cmb=dsResult.Tables[0].Select("Controls Like 'cmb%'");// Here i m getting four Rows for(i=0;i<cmb.Length;i++) { cmb[i]=Session["cmb'+i].ToString().Trim()//Here i m getting error;Cannot implicitly convert type 'string' to 'System.Data.DataRow' } How to assign my session values to them. I want to assign my value stored in the session variable to that array.Is there any way i can do it.Can i convert datarow array to string array! Please can any one help me.
View Replies !
SqlCommand Array Help
I want to do something like the following but I get an error: Object reference not set to an instance of an object. SqlConnection sqlConnection = new SqlConnection("server=xxxxx"); SqlCommand [] cmd = new SqlCommand[3]; Object returnValue; cmd[0].CommandText = "DO QUERY"; cmd[1].CommandText = "DO QUERY"; cmd[2].CommandText = "DO QUERY"; cmd[3].CommandText = "DO QUERY"; } sqlConnection.Open();int i = 0;while(i<4){ cmd[i].CommandType = CommandType.Text; cmd[i].Connection = sqlConnection; cmd[i].ExecuteNonQuery(); returnValue[i] = cmd[i].ExecuteScalar();i++} sqlConnection.Close();How should I do the followingThanks
View Replies !
Array In WHERE Clause
Hello, how can I use an array in a WHERE clause? If I had an array saystring[] NamesArray = new string[] {"Tom", "***", "Harry"} How would I do this:string myquery = "SELET name, city, country FROM myTable WHERE name in NamesArray" Thanks in advance,Louis
View Replies !
Array Problem
Hi All, I have this code below:Dim a As Integer = 0 While a <= myArray.Length() Conn.Open() Dim UpdateCmd As New SqlClient.SqlCommand("Update email_addr SET category = 'Deleted' where HP = @hp", Conn) UpdateCmd.Parameters.Add("@hp", SqlDbType.VarChar, 50).Value = myArray(a) UpdateCmd.ExecuteNonQuery() a = a + 1 Conn.Close() End While BUt, When I run it, I receive error "Prepared statement '(@hp varchar(50))Update email_addr SET category = 'Deleted' wher' expects parameter @hp, which was not supplied. " DOes anyone have the solution??? Thanks....
View Replies !
SQL Query In A VB.net Array
I want to do a query on an SQL Server 2005 db and have the results returned into aarray or collection in vb.net... how do I do this? I know the basicconnection and stuff.. just not how to get the result to an array thanks!
View Replies !
Get Array Value From A Loop?
Hi, I am trying to do a loop while a list of array is assigned ('CHP,CNH,COW') ... I am using comma seperator to get each list value ... but, it donest really do what I am trying to do ... pls help!!! How do I loop through each value and do the rest ...?? ===================================== DECLARE @ABBR AS NVARCHAR(50)SET @ABBR = 'CHP,CNH,COW' DECLARE @SEP AS NVARCHAR(5)SET @SEP = ',' WHILE patindex('%,' + @ABBR + ',%', @ABBR ) > 0 BEGIN -- do the rest END
View Replies !
Result Set Into Array
Hi All, How can I read a query result set (which are of type VARCHAR) into an array? i.e the result set comprises of just one column and 5 rows and i want to save these into an array to easily extract each row whenever i want to. Hope I have conveyed my idea clearly. Gayathri
View Replies !
How To Identify An Array
I have seen several examples explaining the fact that a tablecontaining a field for each day of the week is for the most part anarray. An specific example is where data representing worked hours isstored in a table.CREATE TABLE [hoursWorked] ([id] [int] NOT NULL ,[location_id] [tinyint] NOT NULL,[sunday] [int] NULL ,[monday] [int] NULL ,[tuesday] [int] NULL ,[wednesday] [int] NULL ,[thursday] [int] NULL ,[friday] [int] NULL ,[saturday] [int] NULL)I had to work with a table with a similar structure about 7 years agoand I remember that writing code against the table was pretty close toHell on earth.I am now looking at a table that is similar in nature - but different.CREATE TABLE [blah] ([concat_1_id] [int] NOT NULL ,[concat_2_id] [int] NOT NULL ,[code_1] [varchar] (30) NOT NULL ,[code_2] [varchar] (20) NULL ,[code_3] [varchar] (20) NULL ,[some_flg] [char] (1) NOT NULL) ON [PRIMARY]The value for code_2 and code_3 will be dependently null and they willrepresent similar data in both records (i.e. the value "abc" can existin both fields) . For example if code_2 contains data then code_3 willprobably not contain data.I do not think that this is an array. But with so many rows wherecode_2 and code_3 will be NULL something just does not feel right.I will appreciate your input.
View Replies !
Array In SQL Server
How would one implement an array in SQL Server ? Specically, i'm parsing a field into the array, and doing operations on these elements. Thanks.
View Replies !
Array In A STOC??
Hi all, My Issue is the next thing: I have a table filled with contracts I have Stoc that checks if contract has expired If I start the Stoc I must give it the contractnumber with it like: SP_expired 8 This works fine but now I want that the Stoc checks all the contracts by just starting the Stoc. I don't really know how to do this, I have thinking about using an array. But don't have an idea where to start.... Thnx in advance
View Replies !
|