ado.net

collie

New member
ado.net

Hi, I am starting to use ado.net and i am totally lost. I need to retrieve values from the db and enter those values into a label and a textbox. Using classic ado i wrote something like rs.open ("select *...where ad_id="&ad_id) name=rs("name").value label1.text=name. Don't know how to do it in ado.net. Can someone please help me? Thanks This is what i have so far in aspx.vb Imports System.Data.SqlClient Imports YTools.Constants Private oConn As New SqlConnection(Constants.SQLProviderConnectionString) Private cmd As SqlCommand ad_id = Request.QueryString("ad_id") Dim myDR As SqlDataReader cmd.CommandText = "SELECT * FROM ads,users WHERE AD_ID = " & ad_id & " AND ADS.AD_POSTER = USERS.U_ID" oConn.Open() myDR = myCommand.ExecuteReader​
 

gooshi

New member
Try this

This example helps you bind a data source to a datagrid you can change it a little bit inorder to populate a TextBox, but the main idea is very similar: Imports System Imports System.Data Imports System.Data.SqlClient Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid Public Sub fillTable() Dim oConn As New SqlConnection(CONNECTION_STRING) Dim cmd As SqlCommand Dim DR As SqlDataReader Dim Da As New SqlDataAdapter Dim ds As New DataSet 'For DataReader Exmple 'cmd = oConn.CreateCommand 'cmd.CommandText = "select * from myTable" 'DR = cmd.ExecuteReader 'DataGrid1.DataSource = DR 'For DataSet Exmple oConn.Open() cmd = New SqlCommand("select * from myTable", oConn) Da.SelectCommand = cmd Da.Fill(ds) DataGrid1.DataSource = ds.Tables(0) 'any Exmaple DataGrid1.DataBind() 'For DataReader Exmple 'DR.Close() 'For DataSet Exmple ds.Dispose() oConn.Close() End Sub End Class Good Luck​
 

collie

New member
i succeeded with the code

Private ad_id As Long Private cat_id As Long Private sub_id As Long Private sid As String Private ad_title As String Private ad_poster As String Private poster_email As String Private email_from As String Private message As String Private html As String Private fname As String = "service" Private strConnstr As String Private oConn As New SqlConnection(Constants.SQLProviderConnectionString) Private cmd As SqlCommand oConn.Open() Dim sSQL As String = "SELECT * FROM ybay_mdb...ads ADS left join ybay_mdb...users USERS on ADS.AD_POSTER = USERS.U_ID WHERE AD_ID = @ad_id" Dim myCMD As New SqlCommand(sSQL, oConn) myCMD.Parameters.Add("@ad_id", ad_id) Dim dr As SqlDataReader dr = myCMD.ExecuteReader() Do While dr.Read poster_email = (dr.Item("u_email")) lblReply.Text = (dr.Item("ad_poster")) txtTopic.Text = "Re:" & (dr.Item("ad_title")) & "From Administrator" Loop oConn.Close()​
 
למעלה