Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I used this code. but i cant get its datavaluefield in where condition to another query. Any one plz can help me.

VB
cmdq2.Dispose()
cmdq2.Parameters.Clear()
cmdq2.Connection = con
cmdq2.CommandType = CommandType.StoredProcedure
cmdq2.CommandText = "sp_inout"

cmdq2.Parameters.Add("@companyid", SqlDbType.BigInt).Value = Session("maincompanyid")
cmdq2.Parameters.Add("@contactid", SqlDbType.BigInt).Value = Session("Customer_id")
cmdq2.Parameters.Add("@invoiceid", SqlDbType.Int).Value = cash_invid
cmdq2.Parameters.Add("@currency", SqlDbType.Char).Value = currency
'****************
Dim idr As SqlDataReader = cmdq2.ExecuteReader()


If idr.Read Then
    If idr.HasRows = True Then

        ddlinv.Items.Add(idr(1).ToString())
        ddlinvid = idr(0).ToString
        ddlinv.DataValueField = idr(0).ToString()
        ddlinv.DataTextField = idr(1).ToString()
        idr.Close()
    Else

    End If
End If
Posted

I tried this coding. Its working well.


VB
cmdq2.Dispose()
                    cmdq2.Parameters.Clear()
                    cmdq2.Connection = con
                    cmdq2.CommandType = CommandType.StoredProcedure
                    cmdq2.CommandText = "sp_inout"

                    cmdq2.Parameters.Add("@companyid", SqlDbType.BigInt).Value = Session("maincompanyid")
                    cmdq2.Parameters.Add("@contactid", SqlDbType.BigInt).Value = Session("Customer_id")
                    cmdq2.Parameters.Add("@invoiceid", SqlDbType.Int).Value = cash_invid
                    cmdq2.Parameters.Add("@currency", SqlDbType.Char).Value = currency
                    'Using Datareader to set DatavalueField and Datatextfield
                    Dim idr As SqlDataReader = cmdq2.ExecuteReader()
                    If idr.Read() Then
                        Dim item As ListItem = New ListItem()
                        item.Text = idr("invoiceno").ToString()
                        item.Value = idr("invoiceid").ToString()
                        ddlinv.Items.Add(item)
                    End If
 
Share this answer
 
use DataSet instead Of DataReader because it is disconnected Source of architecture

and then

VB
Con = New SqlConnection("Your ConnectionString")
Con.Open()
Cmd = New SqlCommand("Select * from Products")
dt = New SqlDataAdapter("Select ProductId,ProductName+ProductPrice as Name from    Products", Con)
' Using System.Data;
Dim ds As New DataSet()
'FillDataSet
dt.Fill(ds)
'Bind Drodown
DropDownList1.DataSource = ds
DropDownList1.DataTextField = Convert.ToString(ds.Tables(0).Rows(0)("Name"))
DropDownList1.DataValueField = Convert.ToString(ds.Tables(0).Rows(0)("Id"))
DropDownList1.DataBind()
Con.Close()
 
Share this answer
 
Comments
Jayanthi Muthusamy 11-Apr-11 2:21am    
Thanks for ur immediate reply. I'm using this process within while loop. So if i use dataset concept i cant get row by row results. thats y i used datareader. Is there any possibility to set these properties in datareader? Could u plz help me?
Mahendra.p25 11-Apr-11 2:26am    
try this link

http://bytes.com/topic/c-sharp/answers/230640-dropdownlist-sqldatareader
Jayanthi Muthusamy 11-Apr-11 3:40am    
Hi Mahen,
Thanks to consider my post. I got answer to this problem. We can set DataValueField and DataTextfield property when using datareader. If u see my doubts plz help me. Thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900