|
Your padawan says thanks.
|
|
|
|
|
Based on what Pete already offered, I would try this:
private void SaveImageToDb(string fileName, SqlConnection sqlConnection)
{
using (SqlCommand sqlCmd = new SqlCommand(
"INSERT INTO MyTable(MyImage) VALUES (@Image)", sqlConnection ))
{
sqlCmd.Parameters.Add( "@Image", SqlDbType.VarBinary);
sqlCmd.Parameters [ "@Image" ].Value = File.ReadAllBytes(fileName);
sqlCmd.ExecuteNonQuery( );
}
}
}
Warning: MSDN on SqlDbType.VarBinary holds a comment on size; something happens around 8000 bytes!
|
|
|
|
|
And that would do it nicely.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
using (SqlConnection sqlConnection = new SqlConnection(strConn))
{
sqlConnection.Open();
foreach (string file in fileList)
{
FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
byte[] byteImage = new byte[fileStream.Length];
fileStream.Read(byteImage, 0, (int)fileStream.Length);
string commandText = "Insert into ImageTable(ImagePath, Image)Values(@ImagePath, @Image)";
SqlCommand sqlCommand = new SqlCommand(commandText, sqlConnection);
sqlCommand.Parameters.Add("@ImagePath", SqlDbType.Text);
sqlCommand.Parameters.Add("@Image", SqlDbType.Binary);
sqlCommand.Parameters["@ImagePath"].Value = file;
sqlCommand.Parameters["@Image"].Value = byteImage;
sqlCommand.ExecuteNonQuery();
System.Windows.Forms.Application.DoEvents();
}
}
|
|
|
|
|
Hi,
How to make a part of the text as superscript in button text. Thanks in advance.
|
|
|
|
|
In order to do this, you have to take responsibility for drawing the button yourself. You should search for owner drawn buttons in Google or Bing.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
I have loaded the image after resized to 800x600 (from original image size). but the image aligned at center (picture box size mode is in zoom). how can i align the image at left corner.
code for resize the image
private void resizeimage(Image my, Size sz1)
{
double ratio = 0d;
double myThumbWidth = 0d;
double myThumbHeight = 0d;
int x = 0;
int y = 0;
Bitmap bp;
if (f == false)
{
if ((my.Width / Convert.ToDouble(sz1.Width)) > (my.Height /
Convert.ToDouble(sz1.Height)))
ratio = Convert.ToDouble(my.Width) / Convert.ToDouble(sz1.Width);
else
ratio = Convert.ToDouble(my.Height) / Convert.ToDouble(sz1.Height);
}
else if (f == true)
{
if ((Convert.ToDouble(sz1.Width) / my.Width) > (Convert.ToDouble(sz1.Height)) / my.Height)
ratio = Convert.ToDouble(my.Width) / Convert.ToDouble(sz1.Width);
else
ratio = Convert.ToDouble(my.Height) / Convert.ToDouble(sz1.Height);
}
myThumbHeight = Math.Ceiling(my.Height / ratio);
myThumbWidth = Math.Ceiling(my.Width / ratio);
Size thumbSize = new Size((int)myThumbWidth, (int)myThumbHeight);
bp = new Bitmap(sz1.Width, sz1.Height);
x = (sz1.Width - thumbSize.Width) / 2;
y = (sz1.Height - thumbSize.Height);
System.Drawing.Graphics g = Graphics.FromImage(bp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
rect = new Rectangle(x, y, thumbSize.Width, thumbSize.Height);
g.DrawImage(my, rect, 0, 0, my.Width, my.Height, GraphicsUnit.Pixel);
pictureBox1.Image = bp;
|
|
|
|
|
I got it. I put Zero '0' instead of x and y coordinates. now there is lot of space on right hand side how i remove this.
|
|
|
|
|
How to bring an excel in to windows form. The excel sheet should displayed with in the windows form. Please help
|
|
|
|
|
Hi
Is there any tool to show the ASP.Net application latency when we increase the load ?
Thanks
|
|
|
|
|
I think (haven't checked), but think there is a bunch of performance counters available in the Performance Monitor application with the OS.
There are tools available on the net, some free, just search google for "ASP.Net stress test" etc.
|
|
|
|
|
Hi everyone
How to insert the records in the dataset into the database. i tried the adapter.update(ds). but it does not work...
thank you for reading
zheng
|
|
|
|
|
DataAdapters, and Update in particular, are very limited in what they can do -- I avoid them.
I've forgotten the details, but generally (for SQL Server):
0) Set a Command : INSERT INTO table (field0 ... ) VALUES (@Param0 ... )
1) Create the parameters : cmd.Parameters.Add ( new SqlParameter ( "@Param0" , typeof(whatever) ) )
2) Iterate the rows of a DataTable : foreach ( DataRow dr in ds.Table [ i ].Rows )
2.1) Set the parameter values : cmd.Parameters [ 0 ].Value = dr [ 0 ] ...
2.2) Execute the cmd : cmd.ExecuteNonQuery()
3) Repeat as necessary
I prefer to encapsulate this into a method so I don't need to remember it.
|
|
|
|
|
hi
thank you for reply!
below is my code:
string SelectSchema = "SELECT * FROM [Package Data Range]";
DataSet ds = new DataSet();
OleDbDataAdapter adapterPkInfo = new OleDbDataAdapter(SelectSchema, ImportCon);
OleDbCommandBuilder cmdBldr = new OleDbCommandBuilder(adapterPkInfo);
adapterPkInfo.FillSchema(ds, SchemaType.Source, "PackageDataRangeSchema");
DataSet ds2 = new DataSet();
string selectPkInfo = "SELECT * FROM [Package Data Range]";
OleDbDataAdapter adapter = new OleDbDataAdapter(selectPkInfo, connection);
adapter.Fill(ds2, "Package Data Range");
ds.Tables[0].Merge(ds2.Tables[0],true,MissingSchemaAction.Ignore);
my dataet has around 200 columns. it is not efficient to repeat that....
thank you
zheng
|
|
|
|
|
shoubi wrote: it is not efficient to repeat that
Indeed, but as long as you want to insert all of them, you can loop through the columns and cobble up the Insert statement and parameters.
|
|
|
|
|
yup. thank you very much! however just want to check with you the "adapter.update()" how does it work? does it require any commands? or it is smart enough to act accordingly?
thank you!
|
|
|
|
|
It requires a SELECT command from which it (actually a CommandBuilder) can produce INSERT, UPDATE, and DELETE commands.
Generally, the data must involve one table, have a primary key, and not contain duplicates.
|
|
|
|
|
ok! thank you
|
|
|
|
|
Hi All
This post got actually 2 questions but related each other. I hope you can help me even just solving one of the 2.
In Windows I usually call NETSTAT to have information regarding the status of my network connections.
I am interested in getting the data below produced by Netstat using C#.
*Local Address
*The state of the connection.
Active Connections
Proto Local Address Foreign Address State
TCP ITA-2317A:3377 server1.mylan.co.uk:50506 FIN_WAIT_2
TCP ITA-2317A:3378 server1.mylan.co.uk:50507 FIN_WAIT_2
I am interested in catching the FIN_WAIT_2 state that sometimes is causing me some problems.
My C# application sometimes leaves the network connection in this state..do you know some possible workaround? I am using TcpClient class and I use Close() method..after I do this what check can I do to make sure that my connection is not in the FIN_WAIT_2 state?
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:17am.
|
|
|
|
|
Thanks! I am testing this right now..I have a small doubt bit trivial.
I use embed the NetworkStream in a StreamReader like this
NetworkStream aStream = _client.GetStream();
StreamReader reader = new StreamReader(aStream);
calling reader.Close() does it safely close also the NetworkStream
underlying or do I have to keep a reference to the NetworkStream and close it explicitly?
|
|
|
|
|
I'm trying to run this code within Visual Studio 2010, however, having set a breakpoint at line 39, the execution does not seem to get to line 39 where I have set a break point. As a matter of fact, when checking under Visual Studio 2010 Server Explorer > Servers > {puter name} > Application > ASP.NET 4.0.30319.0, there are no relevant events written. I also tried checking within the Windows Event Viewer. For Win XP (Control Panel > Administrative Tools > Event Viewer > Application sub node).
Is this a bug with .NET 4 or Visual Studio 2010? Does this issue happen to anyone else?
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Diagnostics;
public partial class ErrorTestLog : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void cmdCompute_Click(object sender, EventArgs e)
{
try
{
decimal a, b, result;
a = Decimal.Parse(txtA.Text);
b = Decimal.Parse(txtB.Text);
result = a / b;
lblResult.Text = result.ToString();
lblResult.ForeColor = Color.Black;
}
catch (Exception err)
{
lblResult.Text = "<b>Message:</b> " + err.Message + "<br /><br />";
lblResult.Text += "<b>Source:</b> " + err.Source + "<br /><br />";
lblResult.Text += "<b>Stack Trace:</b> " + err.StackTrace;
lblResult.ForeColor = Color.Red;
EventLog log = new EventLog();
log.Source = "DivisionPage";
log.WriteEntry(err.Message, EventLogEntryType.Error);
}
}
}
NOTE:
1. Beginning ASP.NET 3.5 in C# in 2008 - From Novice to Professional (ISBN: 978-1-59059-891-7) P.268 (306)
Jon
|
|
|
|
|
Does your exception block throw an exception? Do you have a generic exception handler? Does your IIS user have access to write to the event log? Did you use System.Diagnostics.EventLog.CreateEventSource and System.Diagnostics.EventLog.WriteEntry? (Probably not, since you new'd EventLog)
|
|
|
|
|
Does your exception block throw an exception?
No, but throwing the exception prior to calling the event log makes the logging code unreachable, and, this works fine within Visual Studio 2010.
Do you have a generic exception handler?
No, because it is not required for now.
Does your IIS user have access to write to the event log?
I am using Administrator on a local PC, what user does VS 2010 use (to confirm)?
Did you use System.Diagnostics.EventLog.CreateEventSource and System.Diagnostics.EventLog.WriteEntry? (Probably not, since you new'd EventLog)
System.Diagnostics.CreateEventSource is not even shown up within Visual Studio 2010, even though it's a static method. Problem with Intellisense maybe.
Jon
|
|
|
|
|