Skip to content

Instantly share code, notes, and snippets.

@SajjadArifGul
Created October 10, 2015 10:15
Show Gist options
  • Save SajjadArifGul/3b08af4d0b5daa06cc1b to your computer and use it in GitHub Desktop.
Save SajjadArifGul/3b08af4d0b5daa06cc1b to your computer and use it in GitHub Desktop.
try
{
long UserID = Convert.ToInt64(UserIDBox.Text);
/*path to my Database*/
string MyDatabasePath = @"Data Source=.\sqlexpress;Initial Catalog=MyTests;Integrated Security=True";
using (SqlConnection connection = new SqlConnection(MyDatabasePath))
{
connection.Open();
SqlCommand com = new SqlCommand("select * from UserInfo where UserID = '" + UserID + "'", connection);
SqlDataReader read = com.ExecuteReader();
while (read.Read())
{
UserNameBox.Text = (read["UserName"].ToString());
}
read.Close();
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "select UserPicture from UserInfo where UserID='" + UserID + "'";
SqlDataAdapter da = new SqlDataAdapter(command);
SqlCommandBuilder cbd = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
connection.Close();
byte[] ap = (byte[])(ds.Tables[0].Rows[0]["UserPicture"]);
MemoryStream ms = new MemoryStream(ap);
PictureBox.Image = Image.FromStream(ms);
ms.Close();
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment