Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

sqldatareader (no replies)

$
0
0
i am trying to fetch next record using next button but i am getting error i am using sqldatareader to achive this reader is not closed i have closed the reader but still then the next record is not fetched into thte textboxes

using System;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace datareadery
{
public partial class Form1 : Form
{
MySqlDataReader reader;

MySqlCommand cmd;


MySqlConnection con;
public Form1()
{
InitializeComponent();
}


private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
con = new MySqlConnection(@"server=localhost;User Id=root;database=employee");
con.Open();
cmd = new MySqlCommand("select id ,first_name,last_name,start_date from employee", con);

reader = cmd.ExecuteReader();
call();
}
public void call()
{

while (reader.Read())
{
textBox1.Text = reader[0].ToString();
textBox2.Text = reader[1].ToString();
textBox3.Text = reader[2].ToString();
textBox4.Text = reader[3].ToString();

break;

}
}
public void clear()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
private void btnnext_Click(object sender, EventArgs e)
{
call();
con.Close();
}



private void btnclear_Click(object sender, EventArgs e)
{
clear();
}
}
}

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>