.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Bind an image from mssql database to picturebox and navigate it

Posted By: Mahaveer     Posted Date: March 06, 2013    Points:5   Category :C#
i have four textboxes and one picturebox. i want to bind data from ms sql database to c# windows form and want to navigate with buttons(previous,next,first,last)for it i have done this code so far. all records are properly coming from database. i have problem only with image data. when i click on buttons(previous,next,first,last) all records are navigate according to my need but image data is not navigating ? like all other records i also want to bind image data from database and want to navigate like other records with these buttons(Prvious,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=DEEPAK-PC\\SQLEXPRESS2008;Initial Catalog=Animatix;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter();

public Form1()

private void Form1_Load(object sender, EventArgs e)
cmd = new SqlCommand("select * from Add_New_Staff", con);
adp = new SqlDataAdapter(cmd);
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 button1_Click(object sender, EventArgs e)//previous
this.BindingContext[ds.Tables[0]].Position -= 1;

private void button2_Click(object sender, EventArgs e)//next
this.BindingContext[ds.Tables[0]].Position += 1;

private void button3_Click(object sender, EventArgs e)//first
this.BindingContext[ds.Tables[0]].Position = 0;

private void button4_Click(object sender, EventArgs e)//last
this.BindingContext[ds.Tables[0]].Position = this.BindingContext[ds.Tables[0]].Count - 1;



No response found. Be the first to respond this post
Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend