|
i think following code will help u:
1st Step: Take pic. box
2nd Step: Take a Button and Text box to take the image, which u want to save into Database
private void btnBrowse_Click(object sender, System.EventArgs e)<br />
{<br />
OpenFileDialog ofd = new OpenFileDialog( ) ;<br />
ofd.Filter = "Image files |*.jpg" ;<br />
if ( ofd.ShowDialog( ) == DialogResult.OK ) <br />
{ <br />
txtPath.Text = ofd.FileName ; <br />
try<br />
{<br />
FileStream f = new FileStream ( txtPath.Text, FileMode.Open ) ;<br />
byte[ ] buff = new byte [ f.Length ] ;<br />
f.Read ( buff, 0, ( int ) f.Length ) ;<br />
MemoryStream ms= new MemoryStream(buff,0,buff.Length);<br />
Image i = Image.FromStream ( ms ) ;<br />
img.Image = i ; <br />
f.Close();<br />
}<br />
catch(Exception ee) <br />
{ <br />
MessageBox.Show("An error has occured.\n" + ee.Message); <br />
} <br />
}<br />
}<br />
3rd Step: Create table where take one field which will image type
CREATE TABLE [dbo].[tableName] ([img_name] [image] NULL )
ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
<br />
string dbcon = "data source=ServerName;database=dbName;user id=sa;password=";<br />
private void linklblInsertPicture_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)<br />
{<br />
FileStream st = new FileStream ( txtPath.Text, FileMode.Open ) ;<br />
byte[ ] buff = new byte [ st.Length ] ;<br />
st.Read ( buff, 0, ( int ) st.Length ) ;<br />
<br />
try<br />
{ <br />
using(SqlConnection conn = new SqlConnection())<br />
{ <br />
conn.ConnectionString = dbcon;<br />
conn.Open();<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = conn;<br />
cmd.CommandText = "insert into tableName(imageName) values(@pict)";<br />
cmd.Connection = conn;<br />
cmd.CommandType = CommandType.Text;<br />
cmd.Parameters.Add("@pict",buff);<br />
cmd.ExecuteNonQuery();<br />
}<br />
}<br />
catch(SqlException sqle)<br />
{<br />
Console.WriteLine(sqle.Message);<br />
}<br />
st.Close();<br />
}<br />
<br />
private void linklblShowPicture_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)<br />
{<br />
try<br />
{<br />
using(SqlConnection conn = new SqlConnection())<br />
{<br />
conn.ConnectionString = dbcon;<br />
conn.Open();<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = conn;<br />
cmd.CommandText = "select imageName from tableName where .... ";<br />
\\here u can use track id in datatabel to select, update or delete image<br />
cmd.Connection = conn;<br />
cmd.CommandType = CommandType.Text;<br />
<br />
SqlDataReader r = cmd.ExecuteReader();<br />
if(r.Read())<br />
{<br />
byte[ ] b = ( byte[ ] ) r [ 0 ] ;<br />
MemoryStream st = new MemoryStream( ) ;<br />
st.Write ( b, 0, b.Length ) ;<br />
Image i = Image.FromStream ( st ) ;<br />
img.Image = i ; <br />
}<br />
}<br />
}<br />
catch(SqlException sqle)<br />
{<br />
Console.WriteLine(sqle.Message);<br />
}<br />
}
Thankyou
BILLAH
|
|
|
|
|
|
Hi.
What work do the throw statement, alone.
What exception it force to take place?
Best wishes
|
|
|
|
|
The throw keyword *edit*(when used by itself, alone, i.e. throw; )*/edit* can only be used within a catch block. Throw will simply throw the exception that was caught within the catch block. Last modified: Saturday, May 27, 2006 8:10:31 PM --
|
|
|
|
|
Judah Himango wrote: The throw keyword can only be used within a catch block. Throw will simply throw the exception that was caught within the catch block.
Sorry to correct you, but throw can also be used outside of a catch block. The general purpose of this is to initiate an user generated exception. E.g.
if (!File.Exists("test.txt")) {
throw new FileIOException("File was not found");
}
else {
....
}
Graham.
|
|
|
|
|
Graham N wrote: Sorry to correct you, but throw can also be used outside of a catch block.
Sorry to correct you, but the OP was talking about the throw keyword alone, that is without specifying an exception. That can only be used inside a catch block.
---
b { font-weight: normal; }
|
|
|
|
|
Perhaps I've misread what specifically the OP was asking about. But as you have said, the throw keyword without an exception can only be used inside the catch block. That of course is true.
|
|
|
|
|
I believe the original poster was talking of the throw keyword by itself, rather than throwing an exception instance:
try
{
}
catch
{
throw;
}
|
|
|
|
|
Hi.
I have used "AxInterop.ShockwaveFlashObjects.dll" in my project.
How can I handle write click on it?
There is't any mouse event for it.
Best wishes
|
|
|
|
|
Hello,
I got a weird problem with an sql string and a datetime field.
First the code:
<br />
SqlCommand myCommand = new SqlCommand("SELECT * FROM orders WHERE date = @date", connect);<br />
<br />
myCommand.Parameters.AddWithValue("@date", DateTime.Parse(listOrders.Text.ToString().Substring(0, 19)));<br />
<br />
SqlDataReader myReader2 = myCommand.ExecuteReader();<br />
<br />
while (myReader2.Read())<br />
{<br />
Messagebox.Show(myReader2["amount"].ToString() + " | " +products = myReader2["productid"].ToString());<br />
}<br />
The table orders exists of a few rows which are added for testing purposes.
Some are added by hand (so in the "show table data" window), others are added by a form with a datetime.now value.
Now the weird thing is that the query gets a result when the date of the row was added by hand, but when the date of the row was added by the other form, it doesn't get a result (so the while loop isn't executed).
I don't understand why this goes wrong?
Can somebody plz help?
Tnx!
|
|
|
|
|
So, the form doesn't insert data? Or it inserts date but not with the values you expect? Either way, it would appear to be a problem with the way that the data is inserted, not with the way it is retrieved.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
No, it's really weird, I will give you exact copies of the values I find in the date field.
By Hand:
23/10/1986 20:24:23
Inserted data:
26/05/2006 12:39:48
So the data is EXACTLY the same (as far as I know).
That's why I cannot understand it?
|
|
|
|
|
JelleM wrote: So the data is EXACTLY the same (as far as I know).
The problem is that you don't know enough.
The dates you are looking at cuts the time after the seconds and doesn't show the milliseconds. When you compare if two dates are equal, they have to be equal down to the last millisecond. When you take the truncated date that you see and compare it to the date in the database, they will differ by a fraction of a second, but that is enough for them not to be equal.
To get the exact time you need to make the comparision work, you have to display the date with full precision so that you get the millisecons also.
As you see, identifying records by a datetime value is not a very good method. You should use an id instead.
---
b { font-weight: normal; }
|
|
|
|
|
Tnx for the reply!
But the thing is I don't see the milliseconds (if I show the results in the database), so they must be hidden in some way or another.
But can't I use some sort of * to add to the truncated date, so the query doesn't look at the milliseconds or something like that?
TNX!
|
|
|
|
|
JelleM wrote: But the thing is I don't see the milliseconds (if I show the results in the database), so they must be hidden in some way or another.
They are not so much hidden, as they are not shown. If you read the values from the database and display them using a date format that shows the milliseconds, you'll see them.
JelleM wrote: But can't I use some sort of * to add to the truncated date, so the query doesn't look at the milliseconds or something like that?
You could subtract and add a second from the time, and get the records between the times. But then the time is not unique any more...
As I said, using a datetime value to identify a record is not a very good method.
---
b { font-weight: normal; }
|
|
|
|
|
TNX!
|
|
|
|
|
I changed the date-field temporary to a string-field..
What would be the advantage of using a datetime field instead of a string-field?
TNX!
|
|
|
|
|
When ever i set the size of form more than 1036,800...its again resetting to this size only.
It seems this is the maximum size of form.
But i need big form, is there any way...Pls let me know.
|
|
|
|
|
Have you set the maximum size of the form to 1036, 800? What happens when you maximise the form?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
I think, there is no maximum for the size. I've tried it and it works:
this.Size = new Size(1280, 1024);
|
|
|
|
|
Hi there, my name is Ami. I am currently a student at DeVry University and am taking my first programming class! I am ready to pull my hair out because I can never get any of my programs right and I really want to understand this stuff. (by the way I'm taking C# programming online)
I have a lab that I need help with....I have to design a solution with a Main() method that holds an integer variable named seconds to which I assign a value, create a method to which you pass the value, the method displays the seconds in minutes and seconds (66 sec. = 1 min and 6 sec.)...I go there from hours and so on, if anyone could give a jump start in the right direction I would appreciate it. Thanks, Ami
Ami
|
|
|
|
|
Have you tried DateTime (And it's static members like DateTime.Parse() etc...?)?
turn it to DateTime and it will be easyer then deviding it by 60 and by 24...
|
|
|
|
|
NaNg15241 wrote: Have you tried DateTime (And it's static members like DateTime.Parse() etc...?)?
turn it to DateTime and it will be easyer then deviding it by 60 and by 24...
True, but that is not the point of the exercise. The exercise is trying to teach basic concepts, using examples that everyone will understand, such as how to simple maths in a computer language.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Basically this is what I have so far...
using System;
struct Time
{
public Time(int hh, int mm)
{
hours = hh;
minutes = mm;
seconds = 0;
}
private int hours, minutes, seconds;
}
Time now = new Time(12, 30);
Console.WriteLine(now.hours);
Console.WriteLine(now.minutes);
Console.WriteLine(Now.Seconds);
Ami
|
|
|
|
|
betty_boop wrote: if anyone could give a jump start in the right direction I would appreciate it
Well... Lets see what you know, then we can concentrate on teaching you the bits you don't know.
1. Do you know how to create a method?
2. Do you know how to call a method?
3. Do you know simple maths (such as 66 divided by 60, and 66 modulus 60)?
4. Do you know how to create a variable? And assign a value to it?
5. Do you know how to write information to the console? (This lab appears to be a console application)
For every "yes", you are part way to the solution. If you answer "yes" to all, then you need to learn how to put it all together in order to get your program working.
So, what are your answers to the above questions?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|