TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Goran Bibic
475
2.9k
200.9k
Insert picture in datagrid c#
Apr 5 2018 4:09 PM
Problem line 13 and 38..data column type is image in sql
Or some recomandition to insert into and update pciture from picture box
String cs =
"Data Source=.\\SQLEXPRESS;Initial Catalog=bss;Integrated Security=True"
;
if
(string.IsNullOrEmpty(idTextBox.Text))
{
using
(SqlConnection openCon =
new
SqlConnection(cs))
{
string saveStaff =
"INSERT into dbo.poslovni_partneri (Ime, data) VALUES (@Ime,@data)"
;
using
(SqlCommand querySaveStaff =
new
SqlCommand(saveStaff))
{
querySaveStaff.Connection = openCon;
querySaveStaff.Parameters.Add(
"@Ime"
, SqlDbType.VarChar, 255).Value = imeTextBox.Text;
querySaveStaff.Parameters.Add(
"@data"
, SqlDbType.image).Value = pictureBox.Text;
openCon.Open();
querySaveStaff.ExecuteNonQuery();
openCon.Close();
}
}
}
else
{
using
(SqlConnection openCon =
new
SqlConnection(cs))
{
string saveStaff =
"UPDATE dbo.poslovni_partneri SET Ime=@Ime, data=@data WHERE id="
+ idTextBox.Text;
using
(SqlCommand querySaveStaff =
new
SqlCommand(saveStaff))
{
querySaveStaff.Connection = openCon;
querySaveStaff.Parameters.Add(
"@Ime"
, SqlDbType.VarChar, 255).Value = imeTextBox.Text;
querySaveStaff.Parameters.Add(
"@data"
, SqlDbType.image).Value = pictureBox.Text;
openCon.Open();
querySaveStaff.ExecuteNonQuery();
MessageBox.Show(
"Uspješno ste izmenili stavku!"
,
"Informacija"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
openCon.Close();
}
}
}
For upload picture in picture box use this code and it work...
private
void
button4_Click(object sender, EventArgs e)
{
//Read image file
using
(OpenFileDialog ofd =
new
OpenFileDialog() { Filter =
"JPEG|*.jpg"
, ValidateNames =
true
, Multiselect =
false
})
{
if
(ofd.ShowDialog() == DialogResult.OK)
{
fileName = ofd.FileName;
lblFilename.Text = fileName;
dataPictureBox1.Image = System.Drawing.Image.FromFile(fileName);
}
}
}
Reply
Answers (
5
)
Define variable from count sql command
DateTimeClasss and Debug error