Binding Manager Base

Posted by 001Imahaveer under VB.NET on 12/18/2012 | Points: 10 | Views : 3255 | Status : [Member] | Replies : 1
Imports System.Data.SqlClient
Imports System.Data

Public Class Form1

Dim bm As BindingManagerBase
Dim ds As DataSet
Dim adp As OleDb.OleDbDataAdapter


Sub showrecord(ByVal pos As Integer)
TextBox1.Text = ds.Tables(0).Rows(pos)("c_id")
TextBox2.Text = ds.Tables(0).Rows(pos)("c_name")
TextBox3.Text = ds.Tables(0).Rows(pos)("c_address")
TextBox4.Text = ds.Tables(0).Rows(pos)("c_phone")
TextBox5.Text = ds.Tables(0).Rows(pos)("c_email")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

ds = New DataSet
Dim dt As New DataTable
Dim con As New OleDb.OleDbConnection("provider=sqloledb; server=MICROSOF-FDE61F\SQLEXPRESS; database=Hotel; userid=; password=; Trusted_connection=yes")
con.Open()
adp = New OleDb.OleDbDataAdapter("select*from Booking", con)
adp.Fill(ds, "Booking")
bm = Me.BindingContext(ds, "Booking")
bm.Position = 0
showrecord(bm.Position)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
bm.Position -= 1
showrecord(bm.Position)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
bm.Position += 1
showrecord(bm.Position)

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
bm.Position = 0
showrecord(bm.Position)
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
bm.Position = bm.Count - 1
showrecord(bm.Position)
End Sub


End Class

I have 5 text boxes and five buttons in my code. i used binding manager base to bind data. This code binds data from starting. i want that if i enter any id from middle of sql database in textbox1 and click on Load button it should load data from there. it should also bind data from there. like if i enter from 5th id it should bind data from 5th id. how can i do that.




Responses

Posted by: Satyapriyanayak on: 5/16/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Search_Edit
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
string str;
DataSet ds;

public Form1()
{
InitializeComponent();
}

private void btn_edit_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from student where id='"+ textBox1.Text+"'";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
textBox2.Text=(reader["name"].ToString());
textBox3.Text = (reader["mark"].ToString());
}
reader.Close();
con.Close();
}
}
}

If this post helps you mark it as answer
Thanks

001Imahaveer, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response