|
I still won't read it thoroughly, but it seems better.
To store a NULL, set the value of the parameter to DBNull.Value.
|
|
|
|
|
Put it more in error
Comando.Parameters.Add("@foto1", SqlDbType.Image)DBNull.Value = ConvertImageToByteArray(Image2, ImageFormat.Jpeg);
error:
Error 1 ; expected
Error 2 A static readonly field cannot be assigned to (except in a static constructor or a variable initializer)
Error 3 Cannot implicitly convert type 'byte[]' to 'System.DBNull'
|
|
|
|
|
No .
Comando.Parameters.AddWithVAlue("@foto1", DBNull.Value );
Also, don't bother trying to set the data type; the framework will do that when you set the value.
|
|
|
|
|
Presents no error in the description, but when I run the application the error in
Comando.Parameters.Add("@descricao", System.Data.SqlDbType.VarChar, 50).Value = this.txtDescricao.Text;
Comando.Parameters.AddWithValue("@foto", DBNull.Value).Value = ConvertImageToByteArray(Image1, ImageFormat.Jpeg);
Comando.Parameters.AddWithValue("@foto1", DBNull.Value).Value = ConvertImageToByteArray(Image2, ImageFormat.Jpeg);
error:
if (Comando.ExecuteNonQuery() > 0)
The parameterized query '(@descricao varchar(50),@foto nvarchar(4000),@foto1 nvarchar(400' expects the parameter '@foto', which was not supplied.
|
|
|
|
|
Then I don't know; report the SQL statement.
And remove the Value = ConvertImageToByteArray(Image2, ImageFormat.Jpeg) part.
|
|
|
|
|
It worked like this:
if ((picBrasao.Image != null)
Comando.Parameters.AddWithValue("@foto", DBNull.Value).Value = ConvertImageToByteArray(picBrasao.Image, ImageFormat.Jpeg);
Thank you brother
|
|
|
|
|
As PIEBALDconsult says, you shouldn't even think about concatenating strings to form an SQL command - not only does it leave you vulnerable to SQL Injection attacks which could damage or destriy your database, it also causes significant problems with Images as well.
See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] - it explains why it's a problem and how to save and reload the image properly.
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
Hi All,
Im sure this is very simple but after googling for the past 4 hours i cannot seem to find the correct syntax.
I currenly have a SQL which amongst other tables has a DateTime Coloum in the folllowing Format:
2013-09-11 21:06:08:970
I am currently running the follow query from within my C# Application:
select * from table where errorcode = 448
What I would like to do is:
select * from table where errorcode = 448, where date = today
and also
select * from table where errorcode = 448, where date is between 2013-09-11 00:00:00:000 and 2013-09-11 23:59:59:999
I just cant figure out the correct syntax for the queries though.
Could anybody possible Help?
Many Thanks
SG
|
|
|
|
|
If it's an SQL question (which it is) then it's not a C# question.
Are you using SQL Server? Or another system?
If SQL Server, then perhaps the following will help:
select * from [table] where errorcode = 448 <big>AND</big> CAST([date] AS DATE) = CAST(GETDATE() AS DATE)
P.S.
"has a DateTime Coloum in the folllowing Format:
2013-09-11 21:06:08:970
"
DATETIMEs have no such format; they're stored as numeric values, not strings.
modified 14-Sep-13 23:37pm.
|
|
|
|
|
Perfect!
Thank you PIEBALDconsult!
|
|
|
|
|
DateTime columns in SQL Server do not have a format. So, this means that you're storing dates/times as strings, NOT the DateTime format. Because of this little problem, you cannot use the BETWEEN clause. You MUST convert your column to DateTime and probably reload your data into the database.
|
|
|
|
|
I have one GridControl Form can contain column of type image PictureEdit and 1 Button, when its current right-click the column cell of the selected images and photos from your computer to load. But when I click on the Button will not get the value of the image column, I wrote the following code:
using (MemoryStream stream = new MemoryStream())
{ repositoryItemPictureEdit1.Appearance.Image.Save(stream, ImageFormat.Jpeg);
}
The code on the report when it is run "Object reference not set to an instance of an object."
What do you know with his help, thank you very much.
modified 14-Sep-13 21:08pm.
|
|
|
|
|
Then presumably, repositoryItemPictureEdit1 has not been initialised to refer to anything.
Veni, vidi, abiit domum
|
|
|
|
|
Hi,
Please let me know, where I am doing wrong. because following program is not receiving text from notepad.
Thanks alot
using System;
using System.Diagnostics;
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.Runtime.InteropServices;
namespace READVALUES
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, long wParam, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lParam);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("notepad");
foreach (Process p in processes)
{
string myGotWindow = p.MainWindowTitle;
IntPtr pFoundWindow = p.MainWindowHandle;
const uint WM_GETTEXT = 0x0D;
StringBuilder sb = new StringBuilder();
IntPtr retVal = SendMessage(pFoundWindow, WM_GETTEXT, 100, sb);
textBox1.Text = sb.ToString();
}
}
}
}
|
|
|
|
|
|
Give these definitions a try.
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
The reason for the FindWindowEx is so that you can find the child window that contains the text. If you use the MainWindowHandle, you will retrieve the window title. You need to find the child window whose class name is "Edit".
Also give the string builder an ample initial size. The default size is 16 characters.
I will leave it to you to write the logic to compare the returned number of characters against the stringbuilder's "Capacity" property to determine if you got all the text. If returned length is Capacity -1, there may be more text that you did not retrieve.
Process[] processes = Process.GetProcessesByName("notepad");
foreach (Process p in processes)
{
string myGotWindow = p.MainWindowTitle;
IntPtr pEditWindow = FindWindowEx(p.MainWindowHandle, IntPtr.Zero, "Edit", null);
const uint WM_GETTEXT = 0x0D;
StringBuilder sb = new StringBuilder(1000);
IntPtr retVal = SendMessage(pEditWindow, WM_GETTEXT, (IntPtr)sb.Capacity, sb);
textBox1.Text = sb.ToString();
}
|
|
|
|
|
hi there,
i'm trying to run this code,
WPF Language Translator[^]
1) when i run the proj. it says "Make sure you are connected to internet" while i'm connected already...
2) help me regarding "appId" where to find it,
either it "Primary Account Key" or "Customer ID" or "Customer App Secret"..
|
|
|
|
|
Post in the message section at the bottom of the article - perhaps the author can help you out.
|
|
|
|
|
I told him that 3 hours ago. Some people really don't try to help themselves.
Veni, vidi, abiit domum
|
|
|
|
|
Hi friends :
How can I change "zoom" value in print preview dialog ?
I want to change its value from "Autosize" to "100%".
thank you in advance.
|
|
|
|
|
Try
int PreferredZoomValue = 75;<br />
PrintPreviewDialog dgl = new PrintPreviewDialog();<br />
dgl.PrintPreviewControl.Zoom = PreferredZoomValue / 100f;
|
|
|
|
|
it is true with a little revision :
int PreferredZoomValue = 100;
thank you
|
|
|
|
|
Hi friends :
How can I maximize print preview dialog ? I used the following code but it doesn't maximize completely?
ppdialog.Width = Screen.PrimaryScreen.WorkingArea.Width;
ppdialog.Height = Screen.PrimaryScreen.WorkingArea.Height;
thank you in advance.
|
|
|
|
|
hi there;
i want to embed an application in my form panel ;
i tried this code
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace show_exe
{
public partial class form2 : Form
{
#region Methods/Consts for Embedding a Window
[DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId", SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern long GetWindowThreadProcessId(long hWnd, long lpdwProcessId);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)]
private static extern long GetWindowLong(IntPtr hwnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)]
private static extern bool PostMessage(IntPtr hwnd, uint Msg, int wParam, int lParam);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommands nCmdShow);
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
public enum ShowWindowCommands
{
Hide = 0,
Show = 5,
Minimize = 6,
Restore = 9
}
private const int SWP_NOOWNERZORDER = 0x200;
private const int SWP_NOREDRAW = 0x8;
private const int SWP_NOZORDER = 0x4;
private const int SWP_SHOWWINDOW = 0x0040;
private const int WS_EX_MDICHILD = 0x40;
private const int SWP_FRAMECHANGED = 0x20;
private const int SWP_NOACTIVATE = 0x10;
private const int SWP_ASYNCWINDOWPOS = 0x4000;
private const int SWP_NOMOVE = 0x2;
private const int SWP_NOSIZE = 0x1;
private const int GWL_STYLE = (-16);
private const int WS_VISIBLE = 0x10000000;
private const int WM_CLOSE = 0x10;
private const int WS_CHILD = 0x40000000;
private const int WS_MAXIMIZE = 0x01000000;
#endregion
#region Variables
private IntPtr gpsHandle;
private Process gpsProcess = null;
private ProcessStartInfo gpsPSI = new ProcessStartInfo();
#endregion
private void SetupGPSPanel()
{
this.gpsPanel.Location = new Point(120, 50);
this.gpsPanel.Size = new Size(this.Size.Width-200 , this.Size.Height-200 );
gpsPSI.FileName = "notepad.exe";
gpsProcess = System.Diagnostics.Process.Start(gpsPSI);
gpsProcess.WaitForInputIdle();
gpsHandle = gpsProcess.MainWindowHandle;
SetParent(gpsHandle, this.gpsPanel.Handle);
SetWindowLong(gpsHandle, GWL_STYLE, WS_VISIBLE + WS_MAXIMIZE);
MoveWindow(gpsHandle, this.gpsPanel.Location.X,this.gpsPanel.Location.Y, this.gpsPanel.Width, this.gpsPanel.Height, true);
ShowWindow(gpsHandle, ShowWindowCommands.Show);
SetWindowPos(gpsHandle, 0, 0, 0, this.gpsPanel.Bounds.Width, this.gpsPanel.Bounds.Height, SWP_NOZORDER | SWP_SHOWWINDOW);
}
public form2()
{
InitializeComponent();
}
private void form2_Load(object sender, EventArgs e)
{
SetupGPSPanel();
}
}
}
this code works for notepad application but not for other apps
like photoshop ,dvbviewer , winword
why ???
i hope some body help
thanx in advance
|
|
|
|
|
I'm surprised that even NotePad will work inside a Panel in a Windows Form !
I think the following are relevant to your concerns:
on CP, 2004: [^]
on StackOverFlow, 2011: [^]
I would expect "major" non MS applications, like PhotoShop, to never run inside a WinForm, but, I could be wrong.
I think, in general, it is a very bad idea to ever use an instance of another application inside a WinForms app. You are not going to be able to interact with the other application unless you do some tricks like writing a file to a folder that your WinForms app has set a FileWatcher to fire a callback to you when the folder has changed. Back in the stone-age, in the era of COM, SendKeys was a way for VB to interact with other applications, and it was a royal pain in the arse to use (I hope it's extinct, by now).
MS "hands you" standard techniques for automation with the MS Office tools, and IE, and other companies may offer you some sort of API for their software (even hardware) so you can interact with it indirectly. And, of course, you can have a WPF app in a WinForm, and the reverse.
But, I invite you to consider whether it's really wise to struggle to get Application "X" working inside a WinForm.
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|