15,917,731 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by 143Deepak (Top 35 by date)
143Deepak
20-Aug-12 12:07pm
View
i know sir,but doing like that the code will get big .is there any way or by using any type of loop which return only checked or unchecked no. of checkbox,please go through this code it need any modification than please do it.
void LoadCheckList()
{
string intersts = "";
SqlCommand cmd = new SqlCommand("Select Interests from Demo", cn); // Write your Query i have taken as sample
SqlDataReader dr;
cn.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
intersts = dr["Interests"].ToString();
}
cn.Close();
string[] arr = intersts.Split(',');
foreach (ListItem item in this.CheckBoxList1.Items)
{
foreach (string s in arr)
{
if (item.Text== s)
{
item.Selected = true;
}
}
}
}
143Deepak
20-Aug-12 11:22am
View
sir if u dont mind,will u like to guide me that how to get the checkbox value(checked or unchecked) please provide me a block of code.for inserting data.
143Deepak
20-Aug-12 10:22am
View
sir,i already have the table columns of boolean data types,but i did not understand how to bind the particular checkbox to specific column,and how to get the value at once from groupbox,sir please guide me.
143Deepak
11-Aug-12 10:02am
View
sir i dont understand,what do want to explain,will u like to clear it.
143Deepak
7-Aug-12 5:18am
View
but sir to pivot a table ,the column should be integer on which the aggregations will be applied and i have all of my column in char or varchar.
i tried much after reading your solution but did not get what i want.
know what to do?
143Deepak
4-Aug-12 11:30am
View
Not me sir well done u,thanks a lot.
143Deepak
4-Aug-12 11:06am
View
Final code:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace Images
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
using (SqlConnection connection2 = new SqlConnection("Data Source=.;Initial Catalog=users;Integrated Security=True"))
{
string q = "select photo from images where Id=@EMPID";
connection2.Open();
using (SqlCommand cmd = new SqlCommand(q, connection2))
{
cmd.Parameters.AddWithValue("@EMPID", textBox1.Text);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
byte[] byteBLOBData = (byte[])reader["Photo"];
image2.Image = ToImage(byteBLOBData);
}
}
}
}
}
///
/// Gets the Image from a byte array
///
/// <param name="data"></param>
/// <returns>
public static Image ToImage(byte[] Data)
{
if (Data == null)
{
return null;
}
Image img;
using (MemoryStream stream = new MemoryStream(Data))
{
using (Image temp = Image.FromStream(stream))
{
img = new Bitmap(temp);
}
}
return img;
}
string filename;
byte[] piture;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog Open = new OpenFileDialog();
Open.Filter = "Image Files(*.jpeg; *.jpg; *.bmp)|*.jpeg; *.jpg; *.bmp";
if (Open.ShowDialog() == DialogResult.OK)
{
image2.Image = new Bitmap(Open.FileName);
piture = System.IO.File.ReadAllBytes(Open.FileName);
}
}
SqlConnection connection2 = new SqlConnection("Data Source=.;Initial Catalog=users;Integrated Security=True");
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text != null)
{
string Query = "Insert into images (Id,Photo)values(@id,@pic)";
connection2.Open();
SqlCommand cmd = new SqlCommand(Query, connection2);
cmd.Parameters.AddWithValue("@id",textBox1.Text);
cmd.Parameters.AddWithValue("@pic",piture);
int added = cmd.ExecuteNonQuery();
if (added > 0)
{
MessageBox.Show("Data have been saved.");
}
}
}
}
}
143Deepak
4-Aug-12 11:02am
View
oh sorry sir i got my answer.
143Deepak
4-Aug-12 10:56am
View
Thanks Thanks Thanks Thanks Thanks Thanks Thanks Thanks......
lots of thanks sir every thing is working fine. code can save and display the image perfectly.
sir one thing i want to know at beigning my code was "string q = "select photo from employeeDetails where EmployeeId='" + textBox4.Text + "'";
connection2.Open();
SqlCommand cmd = new SqlCommand(q, connection2);
SqlDataReader reader = cmd.ExecuteReader();"
this code also work fine for inserting data then why u have changed to this " string q = "select photo from employeeDetails where EmployeeId=@EMPID";
connection2.Open();
using (SqlCommand cmd = new SqlCommand(q, connection2))
{
cmd.Parameters.AddWithValue("@EMPID", textBox4.Text);
using (SqlDataReader reader = cmd.ExecuteReader())
{"
Why we use parameter?
143Deepak
4-Aug-12 10:29am
View
sir this is my new save code:-
string filename;
byte[] piture;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog Open = new OpenFileDialog();
Open.Filter = "Image Files(*.jpeg; *.jpg; *.bmp)|*.jpeg; *.jpg; *.bmp";
if (Open.ShowDialog() == DialogResult.OK)
{
image2.Image = new Bitmap(Open.FileName);
piture = System.IO.File.ReadAllBytes(filename);
}
}
SqlConnection connection2 = new SqlConnection("Data Source=.;Initial Catalog=users;Integrated Security=True");
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text != null)
{
string Query = "Insert into images (Id,Photo)values(@id,@pic)";
connection2.Open();
SqlCommand cmd = new SqlCommand(Query, connection2);
cmd.Parameters.AddWithValue("@id",textBox1.Text);
cmd.Parameters.AddWithValue("@pic",piture);
int added = cmd.ExecuteNonQuery();
if (added > 0)
{
MessageBox.Show("Data have been saved.");
}
}
}
but there is an error is generated by this line "piture = System.IO.File.ReadAllBytes(filename);" when i am selecting the image from button1.
"Path cannot be null.
Parameter name: path"
and when i remove error giving line than new error is generated by this line int added = cmd.ExecuteNonQuery(); "The parameterized query '(@id nvarchar(1),@pic nvarchar(4000))Insert into images (Id,Phot' expects the parameter '@pic', which was not supplied."
one more thing sir,this is not my code i have just tried from some where else i think it will work after some edition done by u.
143Deepak
4-Aug-12 10:17am
View
aha! sir u have done GNIIT and I am Doing GNIIT.
143Deepak
4-Aug-12 10:16am
View
lots of thanks sir,really i am very very happy.
ok lets we start.
143Deepak
4-Aug-12 10:08am
View
thanks sir.
143Deepak
4-Aug-12 0:34am
View
no sir, my problem did not solved,and i dont want to make u angry. because i am new in IT field, i could not understand your coded language.
143Deepak
3-Aug-12 11:48am
View
sorry sir i could not understand.And very-very thanks for your help.
the things which i could not understand that is "what is updated in that code."
once again thank u......
143Deepak
3-Aug-12 10:43am
View
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text != null)
{
string Query = "Insert into images (Id,Photo)select '" + textBox1.Text + "','" + image2.BackgroundImage + "'";
connection2.Open();
SqlCommand cmd = new SqlCommand(Query, connection2);
int added = cmd.ExecuteNonQuery();
if (added > 0)
{
MessageBox.Show("Data have been saved.");
}
}
}
sir this is my code for save button.
143Deepak
3-Aug-12 1:21am
View
sir,when i save the image using the above (2 day ago comment)code it is again saving the image in hexa format it means that the code needs to change something.
143Deepak
2-Aug-12 0:19am
View
Great sir,know please tell what to change i should make in my code.
143Deepak
1-Aug-12 11:54am
View
sir in database it is saved like this:-
id photo
1 0x53797374656D2E44726177696E672E4269746D6170
143Deepak
1-Aug-12 11:40am
View
sir, i have changed img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); to img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); but altough it is giving the same problem please help sir.
143Deepak
1-Aug-12 10:21am
View
sir, what about is the problem in the code?
143Deepak
31-Jul-12 23:56pm
View
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Virtual_School_Manager
{
public partial class frmEmployee : Form
{
public frmEmployee()
{
InitializeComponent();
}
SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=VSM;Integrated Security=True");
private void butSave_Click(object sender, EventArgs e)
{
try
{
string Query = "Insert into EmployeeDetails (EmployeeId,Photo)select '" + txtEmployeeId.Text + "','" + pictureBoxEmployee.Image + "'";
connection.Open();
SqlCommand cmd = new SqlCommand(Query, connection);
int added = cmd.ExecuteNonQuery();
if (added > 0)
{
this.Close();
DialogResult result = MessageBox.Show("Data have been saved. Do you want to save another data.", "Employee Detail", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
frmEmployee emp = new frmEmployee();
emp.Show();
}
else
this.Close();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
}
private void butCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void butBrowes_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog Open = new OpenFileDialog();
Open.Filter = "Image Files(*.jpeg; *.jpg; *.bmp)|*.jpeg; *.jpg; *.bmp";
if (Open.ShowDialog() == DialogResult.OK)
{
pictureBoxEmployee.Image = new Bitmap(Open.FileName);
}
}
catch (Exception)
{
throw new ApplicationException("Image loading error...");
}
}
public byte[] ImageToByteArray(Image img)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
}
}
sir this is the code for adding image i used.
143Deepak
31-Jul-12 9:20am
View
sir but the code is still giving error "Parameter is not valid." in line using (Image temp = Image.FromStream(stream))
143Deepak
31-Jul-12 0:43am
View
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace Images
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
using (SqlConnection connection2 = new SqlConnection("Data Source=.;Initial Catalog=VSM;Integrated Security=True"))
{
string q = "select photo from employeeDetails where EmployeeId=@EMPID";
connection2.Open();
using (SqlCommand cmd = new SqlCommand(q, connection2))
{
cmd.Parameters.AddWithValue("@EMPID", textBox1.Text);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
byte[] byteBLOBData =(byte[])reader["Photo"];
image2.Image = ToImage(byteBLOBData);
}
}
}
}
}
///
/// Gets the Image from a byte array
///
/// <param name="data"></param>
/// <returns>
public static Image ToImage(byte[] Data)
{
if (Data == null)
{
return null;
}
Image img;
using (MemoryStream stream = new MemoryStream(Data))
{
using (Image temp = Image.FromStream(stream))
{
img = new Bitmap(temp);
}
}
return img;
}
}
}
This is the code is the debugged code.
143Deepak
31-Jul-12 0:35am
View
sir , i did not understand.
143Deepak
30-Jul-12 0:12am
View
sir,please forget the last 2 reply. the code get debugged and know the error is "Parameter is not valid." in line using (Image temp = Image.FromStream(stream))
143Deepak
30-Jul-12 0:04am
View
sir,now using (Image temp = Images.FromStream(stream)) is giving error "Error 1 The type or namespace name 'FromStream' does not exist in the namespace 'Images' (are you missing an assembly reference?)"
143Deepak
29-Jul-12 23:52pm
View
sir,then i have to change the name of my namespace?
143Deepak
29-Jul-12 12:47pm
View
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace Image
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
using (SqlConnection connection2 = new SqlConnection("Data Source=.;Initial Catalog=VSM;Integrated Security=True"))
{
string q = "select photo from employeeDetails where EmployeeId=@EMPID";
connection2.Open();
using (SqlCommand cmd = new SqlCommand(q, connection2))
{
cmd.Parameters.AddWithValue("@EMPID", textBox1.Text);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
byte[] byteBLOBData =(byte[])reader["Photo"];
image2.Image = ToImage(byteBLOBData);
}
}
}
}
}
///
/// Gets the Image from a byte array
///
/// <param name="data"></param>
/// <returns>
public static Image ToImage(byte[] Data)
{
if (Data == null)
{
return null;
}
Image img;
using (MemoryStream stream = new MemoryStream(Data))
{
using (Image temp = Image.FromStream(stream))
{
img = new Bitmap(temp);
}
}
return img;
}
}
}
sir,every thing is totally right i have checked every thing about 50 times.
143Deepak
29-Jul-12 12:06pm
View
sir, i have changed that but the error is same "Error 1 'Image' is a 'namespace' but is used like a 'type'"
sir, i am also trying my best but i did not get any result.
143Deepak
29-Jul-12 11:45am
View
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
namespace imageact
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
using (SqlConnection connection2 = new SqlConnection("Data Source=.;Initial Catalog=VSM;Integrated Security=True"))
{
string q = "select photo from employeeDetails where EmployeeId=@EMPID";
connection2.Open();
using (SqlCommand cmd = new SqlCommand(q, connection2))
{
cmd.Parameters.AddWithValue("@EMPID", textBox1.Text);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
byte[] byteBLOBData =(byte[])reader["Photo"];
image2.Image = ToImage(byteBLOBData);
}
}
}
}
}
///
/// Gets the Image from a byte array
///
/// <param name="data"></param>
/// <returns>
public static Imageact ToImage(byte[] data)
{
if (data == null)
{
return null;
}
Image img;
using (MemoryStream stream = new MemoryStream(data))
{
using (Image temp = Imageact.FromStream(stream))
{
img = new Bitmap(temp);
}
}
return img;
}
}
}
sir i tried much but no drop down button is appearing
143Deepak
29-Jul-12 11:39am
View
public static Image ToImage(byte[] data)
143Deepak
29-Jul-12 11:38am
View
public static Image ToImage(byte[] data)
143Deepak
29-Jul-12 11:29am
View
sir,i have already used using System.Drawing;.
143Deepak
29-Jul-12 11:16am
View
Error 1 'Image' is a 'namespace' but is used like a 'type' E:\Software\Other\Project\Image\Image\Form1.cs 45 23 Image
Show More