Jump to content
Xtreme .Net Talk

Stuck, I pull mulitlple objects from a table and want to display them as a single row


Recommended Posts

Posted

Need help, I trying to query a table that returns multiple objects (1 column and 3 rows) I want to display the results in one column one row in the datagrid. I actually see a new row in the datagrid for each object returned from the database. Can someone please help display the data in one row, any help would be greatly appreciated.

 

Sub Binddata5()

 

Datagrid5.Visible = "true"

 

Dim myConnection As New SqlClient.SqlConnection()

 

myConnection.ConnectionString = "server=localhost;database=License;user id=ASPNET;password="

 

'First create data reader object

 

Dim sqlStmt As String = "Select Projects.Project_Name from Projects

 

inner join ProjectsXProducts on (ProjectsXProducts.Project_ID=Projects.Project_ID) where ProjectsxProducts.Vendor_ID LIKE '" & DropDownList1.SelectedItem.Value & "'"

 

'Create SQL comand object

 

Dim da As New SqlClient.SqlDataAdapter(sqlStmt, myConnection)

 

Dim ds As New DataSet()

 

da.Fill(ds, "Project_Name")

 

Datagrid5.DataSource = ds.Tables(0).DefaultView

 

Datagrid5.DataBind()

 

myConnection.Close()

 

End Sub

 

<asp:datagrid id="Datagrid5" runat="server" BackColor="#E0E0E0" OnEditCommand="DataGrid_Edit5" OnCancelCommand="DataGrid_Cancel5" OnUpdateCommand="DataGrid_Update5" HorizontalAlign="Center" HeaderStyle-BackColor="#0033ff" HeaderStyle-ForeColor="White" Width="90%" Font-Size="8pt" Font-Name="Verdana" CellSpacing="0" CellPadding="4" GridLines="Both" BorderWidth="1" BorderColor="black" AutoGenerateColumns="false" BorderStyle="Solid">

 

<HeaderStyle ForeColor="White" BackColor="#0033FF"></HeaderStyle>

 

<Columns>

 

<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit">

 

<ItemStyle BackColor="#D4D0C8"></ItemStyle>

 

</asp:EditCommandColumn>

 

<asp:TemplateColumn ItemStyle-HorizontalAlign="Center" ItemStyle-Wrap="True" HeaderStyle-Font-Bold="True" HeaderStyle-HorizontalAlign="Center" HeaderText="Projects">

 

<ItemTemplate>

 

<%# DataBinder.Eval(container.DataItem, "Project_Name") %>

 

</ItemTemplate>

 

<EditItemTemplate>

 

<asp:ListBox Runat="server" SelectionMode=Multiple ID="Listbox1" DataValuefield="Project_ID" DataTextField="Project_Name" DataSource="<%# GetComponent5() %>" />

 

</EditItemTemplate>

 

</asp:TemplateColumn>

 

</Columns>

 

</asp:datagrid>

Posted (edited)

I tried something like that, could you look at my code and tell me why the loop doesn't work. I have it commited out since I couldn't fiqure out how to get to work.

Sub Binddata5()
       Datagrid5.Visible = "true"
       Dim myConnection As New SqlClient.SqlConnection()
       myConnection.ConnectionString = "server=10.146.200.38;database=License;user id=ASPNET;password="
       myConnection.Open()
       '       First create data reader object 
       Dim sql_dr As SqlClient.SqlDataReader
       Dim sqlstr As String = "Select Projects.Project_Name from Projects inner join ProjectsXProducts on (ProjectsXProducts.Project_ID=Projects.Project_ID) where ProjectsxProducts.Vendor_ID LIKE '" & DropDownList1.SelectedItem.Value & "'"
       'Create SQL comand object 
       Dim sql_command As New SqlClient.SqlCommand(sqlstr, myConnection)
       'sql_dr = sql_command.ExecuteReader()
       'While sql_dr.Read()
       '    Dim Project_Name As String
       '    Project_Name = sql_dr("Project_Name")
       '    Response.Write(Project_Name)
       'End While
       'sql_dr.Close()
       Datagrid5.DataSource = sql_command.ExecuteReader()
       Datagrid5.DataBind()
       Datagrid5.DataSource.Close()
       myConnection.Close()

Edited by Robby
Posted

Are you suret that the query is returning a record set?

Try running the query on the database using query analyzer or enterprise manager.

Also with the LIKE, the way you have it must be an exact match

- there are no wildcard characters in the string.

Why don't you just use = or LIKE '%" & ddl.Value & "%'"

 

-lp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...