Why Wont This Multiple Selection Listbox Insert Values Into Db

Jan 19, 2008

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 &nbsp;<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" />&nbsp;</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 &nbsp;
218 </HeaderTemplate>
219 </asp:TemplateField>
220 <asp:TemplateField ShowHeader="False">
221 <EditItemTemplate>
222 &nbsp;
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 &nbsp;
232 </ItemTemplate>
233 </asp:TemplateField>
234 </Fields>
235 </asp:DetailsView>
236 <br />
237 <asp:Label ID="ErrorMessage" runat="server" CssClass="errortext"></asp:Label>&nbsp;<br />
238 &nbsp;
239 &nbsp; &nbsp;&nbsp;</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 1 Replies


ADVERTISEMENT

Multiple Selection Listbox As Data Control?

Aug 28, 2007

 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 1 Replies View Related

Using Asp.net Listbox Control (multiple Selection) And Sproc

Oct 6, 2005

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 1 Replies View Related

How To Insert All The Values From A Listbox Into The Database?

Jun 29, 2004

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 3 Replies View Related

How To Save Listbox Multiple Select Values

Jan 11, 2005

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 3 Replies View Related

Sending Multiple Values From A ListBox To ControlParameter

Dec 15, 2005

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 5 Replies View Related

Passing Multiple Values From A Listbox Into A Stored Procedure

Dec 9, 2007

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 3 Replies View Related

Best Way To Use Listbox Selection In WHERE ... IN (...) Clause?

Aug 30, 2005

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 4 Replies View Related

Transact SQL :: First Values In Multiple Columns Selection

May 19, 2015

I'm trying to run something like this:

Select ID, FIRST(forename), FIRST(surname) from table1
GROUP BY ID;

I know First doesn't work in TSQL, I used to use it in Access and now need to run something like that in TSQL. Simply getting unique ID with first forename and surname, cause there are some dupes in a table.

There are records like:

ID      forename     surname
--------------------------------
1    John    Kormack
1   James  Dope
2   Erin    Dupes
3   Will  Hugh
3    Walter Heisenberg

So I want to pull out:

1 John Kormack
2 Erin Dupes
3 Will Hugh

How can I run it in TSQL?

View 6 Replies View Related

SqlDataSource - Filter By Selection From Listbox - WHERE ([Name] IN ('Alaska','alabama'))

Nov 4, 2006

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 4 Replies View Related

'Insert Into' For Multiple Values Given A Table Into Which The Values Need To Go

Sep 1, 2007

Please be easy on me...I haven't touched SQL for a year. Why given;



Code Snippet
USE [Patients]
GO
/****** Object: Table [dbo].[Patients] Script Date: 08/31/2007 22:09:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Patients](
[PID] [int] IDENTITY(1,1) NOT NULL,
[ID] [varchar](50) NULL,
[FirstName] [nvarchar](50) NULL,
[LastName] [nvarchar](50) NULL,
[DOB] [datetime] NULL,
CONSTRAINT [PK_Patients] PRIMARY KEY CLUSTERED
(
[PID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF


do I get

Msg 102, Level 15, State 1, Line 3

Incorrect syntax near ','.
for the following;




Code Snippet
INSERT INTO Patients
(ID, FirstName,LastName,DOB) VALUES
( '1234-12', 'Joe','Smith','3/1/1960'),
( '5432-30','Bob','Jones','3/1/1960');


Thank you,
hazz

View 3 Replies View Related

Listbox Selected Values

Dec 1, 2005

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 2 Replies View Related

Use Listbox Values To Do Select Statement

May 20, 2007

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 6 Replies View Related

Selected Listbox Values In SQL Statement

Jan 9, 2008

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 1 Replies View Related

Insert Multiple Row Values

Oct 25, 2007

hi everyone
how do i insert multiple rows in a database ?
i came up with something like this after googling but it does not work
INSERT INTO tblSold (LID, BuyerID,Date)select ('759','2106','2441') UNION ALLselect ('0','0','0') UNION ALLselect ('10/25/2007','10/25/2007','10/25/2007')

View 8 Replies View Related

Insert Multiple Values

Jan 5, 2000

i have about 2,000 record and i need to insert them in my table.
how do i insert these informations using this syntax??
au_id au_name au_fname
1003 vivian latin
1005 cecy mani
1004 bili david

insert into autors (au_id, au_name,au_fname)
Values ('1101', 'Rabit','jesicca')


thanks for your time and help.

View 1 Replies View Related

How To Insert Multiple Values

Apr 14, 2014

this is my data

AM1WSJZ1241
AM1WLSU7162
AM1SXBI5100
AM1TWXX0477
AM1MSMQ6167
AM1WRQP1810
AM1HNME1411

i want a query to insert a data in table

View 1 Replies View Related

How Do I Store Multiple Selected Listbox Items

Jan 12, 2008

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 3 Replies View Related

Insert Multiple Values Into One Field

Jul 24, 2006

i can't believe my situation is unique, but my searches for answers have proven fruitless, so please bear with me.i have a date field in my database, and have previously used a simple textbox to allow users to insert a date.  i want to make this a little step a little nicer, however, and have added a dropdown for the month, a textbox for the date (i'm not "good" enough to dynamically change this around for a dropdown list), and a dropdown list for the next few years.what "insert" statement would allow me to accomplish this?  what i currently have doesn't blow up, but neither does it actually insert anything.  here's my statment:<asp:SqlDataSource ID="sdsVersion" runat="server" ConnectionString="<%$ ConnectionStrings:DB %>"    InsertCommand="INSERT INTO [Version] ([Major], [Minor], [Sub], [Rev], [Date]) VALUES (@Major, @Minor, @Sub, @Rev, @Month + '-' + @Day + '-' + @Year)">    <InsertParameters>        <asp:Parameter Name="Major" Type="Int32" />        <asp:Parameter Name="Minor" Type="Int32" />        <asp:Parameter Name="Sub" Type="Int32" />        <asp:Parameter Name="Rev" Type="Int32" />        <asp:ControlParameter ControlID="ddlMonths" Name="Month" PropertyName="SelectedValue" Type="Int32" />        <asp:ControlParameter ControlID="tbDate" Name="Day" PropertyName="Text" Type="Int32" />        <asp:ControlParameter ControlID="ddlYears" Name="Year" PropertyName="SelectedValue" Type="Int32" />    </InsertParameters></asp:SqlDataSource>

View 7 Replies View Related

SQL Server Insert Multiple Values

Dec 30, 2004

I am dynamically creating a sql insert query from a web page that can potentially have multiple values to be inserted into a table. The query I have right now my query is shown below. When it runs, it only inserts one record (the values 24,3). Any ideas what I am doing wrong?

INSERT INTO [tblWebPageByRank]
([WebPageID],[RankID])
Values (24,3,24,5)

View 3 Replies View Related

INSERT Multiple Values With One Query

Oct 26, 2004

I want to know if MS SQL has ability to INSERT multiple values with one statement. For example MySQL is able to do it like so

INSERT INTO myTable (col1,col2,col3)
VALUES
('1','1','1'),
('2','2','2'),
('3','3','3'),
('4','4','4');

and this will insert four rows.

Does MS SQL Have anything similar or do I have to repeat the INSERT statement if I need to generate a dynamic insert?

Thanks,
Lito

View 9 Replies View Related

Insert With Max Values From Multiple Tables

Dec 20, 2007

I am trying to add records to 2 separate tables and each table has a unique ID from the other table. I need to find the highest number ID from both tables (and add 1) and add a record with both new values to both tables.

I have tried the following, but it is not working. Any help would be appreciated, Thanks (my tables are MEMOS and PDSMSGC)


INSERT INTO MEMOS (MemoID, ParentID, FieldName, MemoText)
SELECT MAX(MemoID) + 1 FROM "MEMOS", MAX(MessageID) +1 FROM "PDSMSGC", 'pmc:MemoID', 'Hi my name is bob'
INSERT INTO PDSMSGC (MessageID, MemoID) SELECT MAX(MessageID) + 1 FROM "PDSMSGC", MAX(MemoID) FROM "MEMOS"

View 5 Replies View Related

Insert Values In Multiple Table With Foreign Key

Feb 28, 2008

Hi,

I've been working as web dev for quite sometime now but there are still few things that i would like to clarify. Hope you guys can shed lights.

I currently have several tables and all this tables are having some 1 to many relationships. I know that how i insert value into my tables are very inefficient. I do it in this manner..
-> Insert a value in TableA
-> Query the latest ID that i have inserted in Table A then
-> Insert this value in TableB. And so on and so forth.

I believe there is an efficient way to to do this but i'm not sure how? Could anyone shed me a light on this matter?

Your reply would be highly appreciated. TIA.

View 6 Replies View Related

SQLCeconnection On Visual Basic And Insert Data On A Listbox

Nov 13, 2007



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 4 Replies View Related

T-SQL (SS2K8) :: Insert Multiple Values Based On Parameter

Jul 22, 2014

I need to write SP where user select SUN to MON check boxes. If user select Class A with sun,mon and wed check boxes then i need to insert data as below

CLASS Days
A sun
A Mon
A wed

View 6 Replies View Related

Insert Multiple Rows To Table Based On Values From Other 2 Tables.

Nov 21, 2007

I have a form to assign JOB SITES to previously created PROJECT.  The  JOB SITES appear in the DataList as it varies based on customer. It can be 3 to 50 JOB SITES per PROJECT.
I have "PROJECT" table with all necessary fields for project information and "JOBSITES" table for job sites. I also created a new table called "PROJECTSITES"  which has only 2 columns:  "ProjectId" and "SiteId".
What I am trying to do is to insert multiple rows into that "PROJECTSITES" table based on which checkbox was checked.  The checkbox is located next to each site and I want to be able to select only the ones I need. Btw the Datalist is located inside of a formview and has it's own datasource which already distincts which JOBSITES to display.
Sample:
ProjectId    -    SiteId
1   -   5
1    -   9
1    -   16
1    -   18
1    -   20
1    -   27
1    -   31
ProjectId stays the same, only values for SiteId are being different.
I hope I explaining it right. Do I have to use some sort of loop to go through the automatically populated DataList records and how do I make a multiple inserts to database table? We use SQL Server 2005 and VB for code behind. Please ask if I missed on some information. Thank you in advance.

View 10 Replies View Related

Can Multiple Selection Controls Be Use With SqlDataSource?

Mar 4, 2007

 NET 2.0 
I am using Visual Studio Express 2005 for database web developement.
I have created a database with 5 tables.  Two are associative tables.
They are
SoftwarePK SoftwareID      Title
SoftwareSolutionFK SoftwareIDFK SolutionID
SolutionPK SolutionID     Title
CategorySolutionFK CategoryFK Solution
Category
PK Category     Title 
Criteria for a search with three sources of input into a SqlDataSource attached to a FormView for paged out. 
The following are the Search Criteria input sources:1) ListBox in Multiple Selection Mode2) CheckBoxList with Mutiple checks posible2) TextBox with key word search in Title.
Each Solution has 0 or many Categories and 0 or many Software.
When the records are entered in the database, the associative information for Categories and Software are populated to filter thereturned values.
In NET  1.1, I would create a search string like the following in code behind by looping through the CheckBoxList and ListBox finally adding the TextBox:
SELECT Solution.SolutionID, Solution.Title FROM SolutionWHERE             Solution.SolutionID IN ('2','3','5')      AND             Solution.Title LIKE '%Math%'
I am unable to update the SelectCommand in the ASPX page.
However, when I use the I have used theSystem.Web.UI.WebControls.SqlDataSources"SelectQuery Builder"I receive the following in the Source for ASPX: <asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT Solution.SolutionID, Solution.Title
FROM
Solution INNER JOIN CategorySolution ON Solution.SolutionID = CategorySolution.SolutionID
INNER JOIN SoftwareSolution ON Solution.SolutionID = SoftwareSolution.SolutionID">
<SelectParameters>
<asp:ControlParameter ControlID="CheckBoxList1" DefaultValue="%" Name="CategoryID" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="ListBox1" DefaultValue="%" Name="SoftwareID" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="txtTitleSearch" DefaultValue="%" Name="Title" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource> I receive duplicate records and not sure if the code generated accesses the Mutiple Selected values in the CheckBoxList1 and ListBox1.Question: 1) If the SelectQuery generator will not access multiple selected values from the CheckBoxList1, how can I use code behind to replaceSelectCommand in the ASPX page?2) What is the best solution for using the CheckBoxList1, ListBox1, and TextBox for filtering my results? Sample code, references to solutions, corrections on logic, a new approach, how to use the wizard correctly would all be greatly appreciated.3) Can Multiple Selection Controls be use with a SqlDataSource SELECT Command?Thanks for your time,Sincerely,Unhistoric

View 2 Replies View Related

Date Selection Giving Default '1/1/1900' For NULL Values

Feb 9, 2005

'XXX_DTE' is character type which wont take NULL.

SELECT CONVERT(Datetime,XXX_DTE) FROM XXXX

I get result as : 1/1/1900

Why is it so.....

What I expect is '0000-00-00 00:00:00.000'

View 1 Replies View Related

T-SQL (SS2K8) :: Selection With Conditional Insert Union

Apr 4, 2014

In this selection when there is particular segment found in the selection then need to add 2 records per segment otherwise just selected results

--Drop table #list
CREATE TABLE #LIST ( email varchar(20),Segment varchar(20), Addr1 varchar(20), City varchar(20),ST varchar(20), Code int)
--Drop table #subject
CREATE TABLE #Subject (Segment varchar(20), Fname varchar(20), LName varchar(20))

[Code] ....

---Selection results
SELECT L.Segment , l.email, l.Addr1 , l.City ,l.ST, l.code, s.Fname , s.LName into #expectedresult FROM #LIST L JOIN #Subject S ON l.Segment =s.Segment

--Now here what i am trying to get, union the below two record to the above "selection Results" for only segment ='VEC_BAL' or segment = 'PPC_BAL'

--2 records
SELECT l.segment , l.email , Addr1, City, ST, 999 as Code,'' fname, ''lname from #LIST l where email ='mmm@m.com'
SELECT l.segment , l.email , Addr1, City, ST, 888 as Code, '' fname, ''lname from #LIST l where email ='lrk@m.com'

--- expected results please execute below block ( per each segment 2 records will insert if there is segment ='VEC_BAL' or 'PPC_BAL' ). If there is no Vec_Bal or PPC BAL then no additional inserts, if there is only VEC_BAL no PPC_BAL then only 2 records insert
SELECT L.Segment , l.email, l.Addr1 , l.City ,l.ST, l.code, s.Fname , s.LName into #expctresults1 FROM #LIST L JOIN #Subject S ON l.Segment =s.Segment
union

[Code] .....

View 3 Replies View Related

T-SQL (SS2K8) :: Stored Procedure To Truncate And Insert Values In Table 1 And Update And Insert Values In Table 2

Apr 30, 2015

table2 is intially populated (basically this will serve as historical table for view); temptable and table2 will are similar except that table2 has two extra columns which are insertdt and updatedt

process:
1. get data from an existing view and insert in temptable
2. truncate/delete contents of table1
3. insert data in table1 by comparing temptable vs table2 (values that exists in temptable but not in table2 will be inserted)
4. insert data in table2 which are not yet present (comparing ID in t2 and temptable)
5. UPDATE table2 whose field/column VALUE is not equal with temptable. (meaning UNMATCHED VALUE)

* for #5 if a value from table2 (historical table) has changed compared to temptable (new result of view) this must be updated as well as the updateddt field value.

View 2 Replies View Related

Reporting Services :: Set Default Values For Selection List Navigator For Data Source View

Jul 14, 2015

How to set default values for selection list navigator without using parametrized queries for data source view.

View 2 Replies View Related

Reporting Services :: Selecting Multiple Parameters Values For Comma Separated Values In SSRS?

Jun 17, 2012

I am SSRS user, We have a .net UI from where we want to pass multi select values, but these values are comma separated in the database. how can I write a sql query such that when I select multi values on my UI, the comma separated values are take care of.

View 5 Replies View Related

Retrieving Multiple Values From One Field In SQL Server For Use In Multiple Columsn In Reports

Mar 30, 2007

I am trying to create a report using Reporting Services.

My problem right now is that the way the table is constructed, I am trying to pull 3 seperate values i.e. One is the number of Hours, One is the type of work, and the 3rd is the Grade, out of one column and place them in 3 seperate columns in the report.

I can currently get one value but how to get the information I need to be able to use in my reports.

So far what I've been working with SQL Reporting Services 2005 I love it and have made several reports, but this one has got me stumped.

Any help would be appreciated.



Thanks.



I might not have made my problem quite clear enough. My table has one column labeled value. The value in that table is linked through an ID field to another table where the ID's are broken down to one ID =Number of Hours, One ID = Grade and One ID= type of work.

What I'm trying to do is when using these ID's and seperate the value related to those ID's into 3 seperate columns in a query for using in Reporting Services to create the report

As you can see, I'm attempting to change the name of the same column 3 times to reflect the correct information and then link them all to the person, where one person might have several entries in the other fields.

As you can see I can change the names individually in queries and pull the information seperately, it's when roll them altogether is where I'm running into my problem

Thanks for the suggestions that were made, I apoligize for not making the problem clearer.

Here is a copy of what I'm attempting to accomplish. I didn't have it with me last night when posting.



--Pulls the Service Opportunity

SELECT cs.value AS "Service Opportunity"

FROM Cstudent cs

INNER JOIN cattribute ca ON ca.attributeid = cs.attributeid

WHERE ca.name = 'Service Opportunity'



--Pulls the Number of Hours

SELECT cs.value AS 'Number of Hours'

FROM Cstudent cs

INNER JOIN cattribute ca ON ca.attributeid =cs.attributeid

WHERE ca.name ='Num of Hours'



--Pulls the Person Grade Level

SELECT cs.value AS 'Grade'

FROM Cstudent cs

INNER JOIN cattribute ca ON ca.attributeid =cs.attributeid

WHERE ca.name ='Grade'



--Pulls the Person Number, First and Last Name and Grade Level

SELECT s.personnumber, s.lastname, s.firstname, cs.value as "Grade"

FROM student s

INNER JOIN cperson cs ON cs.personid = s.personid

INNER JOIN cattribute ca ON ca.attributeid = cs.attributeid

WHERE cs.value =(SELECT cs.value AS 'Grade'

WHERE ca.attributeid = cs.attributeid AND ca.name='Grade')

View 11 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved