Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have four textboxes and one picturebox. i want to bind data from ms sql database to c# windows form and want to rotate with buttons(previous,next,first,last)for it i have done this code so far. all records are properly coming from database and rotating. i have problem only with image. it is not rotating . like all other records i also want to bind image from database and want to rotate like other records with these buttons(Previous,next,first,last).

C#
using System;
using System.Collections.Generndic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;

namespace Picbox_working
{
public partial class Form1 : Form
{
SqlConnection con=new SqlConnection("Data Source=SHREY\\SQLEXPRESS;Initial Catalog=MyRecords;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("select * from Add_New_Staff", con);
adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
textBox1.DataBindings.Add("Text", ds.Tables[0], "stid");
textBox2.DataBindings.Add("Text", ds.Tables[0], "sname");
textBox3.DataBindings.Add("Text", ds.Tables[0], "addr");
textBox4.DataBindings.Add("Text", ds.Tables[0], "mobil");
Byte[] data = (Byte[])(ds.Tables[0].Rows[0]["imgdata"]);
MemoryStream mem = new MemoryStream(data);
pictureBox1.Image = Image.FromStream(mem);
}

private void previous_button_Click(object sender, EventArgs e)
{
this.BindingContext[ds.Tables[0]].Position -= 1;
}

private void next_button_Click(object sender, EventArgs e)
{
this.BindingContext[ds.Tables[0]].Position += 1;
}

private void first_button_Click(object sender, EventArgs e)
{
this.BindingContext[ds.Tables[0]].Position = 0; 
}

private void last_button_Click(object sender, EventArgs e)
{
this.BindingContext[ds.Tables[0]].Position = this.BindingContext[ds.Tables[0]].Count - 1;
}

}
}
Posted

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