Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

With vb 6.0 i can do this, set a control source to a textbox:

 

Dim li As New ADODB.Connection
       Dim dados As New ADODB.Recordset
       Dim strSQL As String
       li.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=\Desenvolvimento\Rh Vb v.1.0\rh.mdb;Persist Security Info=False"
       li.CursorLocation = ADODB.CursorLocationEnum.adUseClient

       strSQL = "select * from t_users_logs"

       li.Mode = ADODB.ConnectModeEnum.adModeReadWrite

       li.Open

       dados.Open "t_users_logs", li, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic


       dados.MoveFirst


       Me.Textbox1.DataField = "user_id"



       dados.MoveFirst


       Set Me.Textbox1.DataSource = dados
       

 

All I want to do is this with vb.net, but the property .datafield can't be assigned, it's not available in code.

  • Moderators
Posted

Paste this into the code window of a form....

The controls are:

txt = textbox

btn = button

   Dim dt As DataTable

   Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
       Dim cm As CurrencyManager = BindingContext(dt)
       cm.Position -= 1

   End Sub

   Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
       Dim cm As CurrencyManager = BindingContext(dt)
       cm.Position += 1
   End Sub

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Const sConn As String = "Data Source=127.0.0.1;Initial Catalog=northwind;Integrated Security=True"

       Dim sSQL As String = "Select EmployeeID, FirstName + ' ' + LastName AS FullName from Employees "
       Dim da As New SqlClient.SqlDataAdapter(sSQL, sConn)
       Dim ds As New DataSet()
       da.Fill(ds, "EmployeeList")

       dt = ds.Tables("EmployeeList")

       txtEmployeeID.DataBindings.Add("Text", dt, "EmployeeID")
       txtFullName.DataBindings.Add("Text", dt, "FullName")
   End Sub

Visit...Bassic Software

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...