Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
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).
 
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 7-Mar-13 2:45am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 DamithSL 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100