|
Landie110 wrote: This is the actual code (except for not mentionning the whole query because otherwise it would be too long).
How do you build the query?
|
|
|
|
|
this is the full code:
if (klantID > 0)
{
strSQL = "INSERT INTO [IBAX].[dbo].[klanten] ([klantOndNr],[klantNaam],[klantStraat]" +
",[klantPostcode],[klantGemeente],[klantLand],[klantContact],[klantTelefoon]" +
",[klantGSM],[klantFax],[klantEmail],[klantURL],[klantTaal]) VALUES (";
strSQL = strSQL + "'" + klantOndNr + "', '"
+ klantNaam + "', '"
+ klantStraat + "', '"
+ klantPostcode + "', '"
+ klantGemeente + "', '"
+ klantLand + "', '"
+ klantContact + "', '"
+ klantTelefoon + "', '"
+ klantGSM + "', '"
+ klantFax + "', '"
+ klantEmail + "', '"
+ klantURL + "', "
+ klantTaal + ")";
}
else
{
strSQL = "UPDATE [IBAX].[dbo].[klanten] SET [klantOndNr] = '" + klantOndNr
+ "', [klantNaam] = '" + klantNaam
+ "', [klantStraat] = '" + klantStraat
+ "', [klantPostcode] = '" = klantPostcode
+ "', [klantGemeente] = '" + klantGemeente
+ "', [klantLand] = '" + klantLand
+ "', [klantContact] = '" + klantContact
+ "', [klantTelefoon] = '" + klantTelefoon
+ "', [klantGSM] = '" + klantGSM
+ "', [klantFax] = '" + klantFax
+ "', [klantEmail] = '" + klantEmail
+ "', [klantURL] = '" + klantURL
+ "', [klantTaal] = " + klantTaal
+ " WHERE klantid = " + klantID;
}
|
|
|
|
|
It must be something specificly with the update-instruction.
I've tried it using only the update (so no if...else, always use update) and I've got the same error message.
I've replaced the update with the exact same code for if (the insert-instruction) and then I don't get the error.
I've tried changing the building of the update instruction a little bit but I still get the same error.
|
|
|
|
|
Landie110 wrote: + "', [klantPostcode] = '" = klantPostcode
You have put an assignment operator (=) where the concatenation operator (+) should be.
-- modified at 16:51 Saturday 29th September, 2007
(Incidentally, the swedish word "klant" describes a person that has messed up. )
---
single minded; short sighted; long gone;
|
|
|
|
|
Well, spotted. I just went on a tangent about SQL Injection Attacks. (Well, what else am I going to talk about).
Just as well I asked to see the whole code.
|
|
|
|
|
Colin Angus Mackay wrote: I just went on a tangent about SQL Injection Attacks. (Well, what else am I going to talk about).
ROTFL !!!
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Guffa wrote: (Incidentally, the swedish word "klant" describes a person that has messed up. )
Just as well Landie110 is from Belgium where it means "client".
|
|
|
|
|
So the client is someone who messed up ? I mean, surely there's a link between two european countries using the same word to mean different things ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Are all the variables strings?
Also, it would be better if you didn't inject values into the SQL command as it can lead to SQL Injection Attacks.
sqlSQL = "UPDATE [IBAX].[dbo].[klanten] "+
"SET [klantOndNr] = @klantOndNr, "+
"[klantNaam] = @klantNaam";
mySqlCommand.CommandText = strSQL;
mySqlCommand.Parameters.AddWithValue("@klantOndNr", klantOndNr);
mySqlCommand.Parameters.AddWithValue("@klantNaam", klantNaam);
If you restructure as above, you might find your error easier to find (if it doesn't fix it) AND the security of your application improved.
|
|
|
|
|
I've changed my code to what you suggested and it works.
Thanks !
|
|
|
|
|
HI All,
I am trying to put together a print function but I am having some trouble with it. I have looked at numerous code and have tried to put my own together but I getthe following error message, "Object not reference not set to an instance of an object". I think I know where the problem is but do't know how to fix it.
<br />
public partial class Orders : Form<br />
{<br />
<br />
private PrintDocument printDoc = new PrintDocument();<br />
private PageSettings pgSettings = new PageSettings();<br />
private PrinterSettings prtSettings = new PrinterSettings();<br />
<br />
<br />
<br />
<br />
<br />
<br />
public Orders()<br />
{<br />
MenuItem fileMenuItem = new MenuItem("&File");<br />
MenuItem filePageSetupMenuItem = new MenuItem("Page Set&up...", new EventHandler(filePageSetupMenuItem_Click));<br />
MenuItem filePrintPreviewMenuItem = new MenuItem("Print Pre&view", new EventHandler(filePrintPreviewMenuItem_Click));<br />
MenuItem filePrintMenuItem = new MenuItem("&Print...", new EventHandler(filePrintMenuItem_Click), Shortcut.CtrlP);<br />
<br />
fileMenuItem.MenuItems.Add(filePageSetupMenuItem);<br />
fileMenuItem.MenuItems.Add(filePrintPreviewMenuItem);<br />
fileMenuItem.MenuItems.Add(filePrintMenuItem);<br />
this.Menu = new MainMenu();<br />
this.Menu.MenuItems.Add(fileMenuItem);<br />
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);<br />
<br />
InitializeComponent();<br />
}<br />
<br />
#region Printing Code<br />
<br />
private void filePrintMenuItem_Click(Object sender, EventArgs e)<br />
{<br />
printDoc.DefaultPageSettings = pgSettings;<br />
PrintDialog dlg = new PrintDialog();<br />
dlg.Document = printDoc;<br />
if (dlg.ShowDialog() == DialogResult.OK)<br />
{<br />
printDoc.Print();<br />
}<br />
}<br />
private void filePrintPreviewMenuItem_Click(Object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
<br />
PrintPreviewDialog dlg = new PrintPreviewDialog();<br />
dlg.Document = printDoc;<br />
dlg.FormBorderStyle = FormBorderStyle.Fixed3D;<br />
dlg.SetBounds(20, 20, this.Width, this.Height);<br />
dlg.ShowDialog();<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message.ToString());<br />
}<br />
<br />
<br />
<br />
}<br />
private void filePageSetupMenuItem_Click(Object sender, EventArgs e)<br />
{<br />
PageSetupDialog pageSetupDialog = new PageSetupDialog();<br />
pageSetupDialog.PageSettings = pgSettings;<br />
pageSetupDialog.PrinterSettings = prtSettings;<br />
pageSetupDialog.AllowOrientation = true;<br />
pageSetupDialog.AllowMargins = true;<br />
pageSetupDialog.ShowDialog();<br />
}<br />
<br />
private void printDoc_PrintPage(Object sender, PrintPageEventArgs e)<br />
{<br />
<br />
DrawAll(e.Graphics);<br />
<br />
}<br />
Problem is in here.
private void DrawAll(Graphics g)<br />
{<br />
RectangleF srcRect = new Rectangle(0, 0, this.BackgroundImage.Width, BackgroundImage.Height);<br />
<br />
Then the rest of the code
<br />
int nWidth = printDoc.PrinterSettings.DefaultPageSettings.PaperSize.Width;<br />
int nHeight = printDoc.PrinterSettings.DefaultPageSettings.PaperSize.Height;<br />
RectangleF desct = new Rectangle(0, 0, nWidth, nHeight / 2);<br />
<br />
g.DrawImage(this.BackgroundImage, desct, srcRect, GraphicsUnit.Pixel);<br />
<br />
float scalex = desct.Width / srcRect.Width;<br />
float scaley = desct.Height / srcRect.Height;<br />
<br />
Pen aPen = new Pen(Brushes.Black, 1);<br />
<br />
for (int i = 0; i < this.Controls.Count; i++)<br />
{<br />
if (Controls[i].GetType() == this.t1TextBox.GetType())<br />
{<br />
TextBox theText = (TextBox)Controls[i];<br />
g.DrawString(theText.Text, theText.Font, Brushes.Black, theText.Bounds.Left * scalex, theText.Bounds.Top * scaley, new StringFormat());<br />
}<br />
if (Controls[i].GetType() == this.groupBox1.GetType())<br />
{<br />
GroupBox theGroup = (GroupBox)Controls[i];<br />
Rectangle aRect = theGroup.Bounds;<br />
g.DrawRectangle(aPen, aRect.Left * scalex, aRect.Top * scaley, aRect.Width * scalex, aRect.Height * scaley);<br />
}<br />
if (Controls[i].GetType() == this.orderDateDateTimePicker.GetType())<br />
{<br />
DateTimePicker aPicker = (DateTimePicker)Controls[i];<br />
g.DrawString(aPicker.Text, aPicker.Font, Brushes.Black, aPicker.Bounds.Left * scalex, aPicker.Bounds.Top * scaley, new StringFormat());<br />
}<br />
if (Controls[i].GetType() == this.comboBox1.GetType())<br />
{<br />
ComboBox theCombo = (ComboBox)Controls[i];<br />
Rectangle cRect = theCombo.Bounds;<br />
g.DrawRectangle(aPen, cRect.Left * scalex, cRect.Top * scaley, cRect.Width * scalex, cRect.Height * scaley);<br />
}<br />
<br />
}<br />
}<br />
|
|
|
|
|
It's quite simple. You have forgotten about initializing BackgroundImage and you get null reference error as long as "null" is a default value of BackgroundImage. Try doing this:
BackgroundImage = new Bitmap(Width, Height);
or sth like that, whatever.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Thanx mate. That seems to have worked. Now, while that seems to have worke fine I have fond yet another problem. My textbox details have gone missng or better yet itisnot moved into the print preview. Is my code missing something? The textboxes are all within a Group Box. My labels are also not printing which probably mean I have not declared them. Correct? f you could ave a look at why my text boxes are not comming through I would greatly appreciate it. Cheers
|
|
|
|
|
Well, I have a deep night here in Poland so I am in a "not responding" state. Maybe tomorow I will be able to help you.
PS. I have noticed following expression in your code:
Controls[i].GetType() == this.t1TextBox.GetType()
Why not use the is operator?
Controls[i] is TextBox
Good Night - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
gajatko wrote: deep night here in Poland so I am in a "not responding" state.
I'll have to remember that and put California in place for Poland if I use the same line
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
Thanx guys but I am still having problems with this one. My Text boxes don't seem to print over. I think it may because they are sitting in the GROUPBOX. Any further Ideas?
|
|
|
|
|
Yes. You are enumarating Form.Controls collection, which doesn't contain controls which are in a groupbox. Controls in a groupbox are in the GroupBox.Controls collection.
About printing a form. Did you try to use the Form.DrawToBitmap method?
Bitmap b = new Bitmap(Width, Height);
this.DrawToBitmap(b, new Rectangle(0, 0, Width, Height));
b.Save("test.png");
b.Dispose();
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Thanx mate. I managed to get one of the groupboxs onto the form now. However groupBox1 doesn't seem to be comming over. I have managed to get some code for printing off the codeprojact site which caters for two groupboxes but it doesn't work in my project. Any other ideas?
|
|
|
|
|
i try to write code for create a barcode. i searched in this site for this and found some documents and samples, they show a table for numbers but i couldn't understand clearly. please help me about barcodesss.
signature...
|
|
|
|
|
Can you tell us what you don't understand?
Me: Can you see the "up" arrow?
User:Errr...ummm....no.
Me: Can you see an arrow that points upwards?
User: Oh yes, I see it now!
-Excerpt from a support call taken by me, 08/31/2007
|
|
|
|
|
1- it's not clear that the first digit is not drawn.because some country codes are three digit
2- what is the min and max width of barcode sticks.
3- what is the odd and even standart and which binary numbers will be used.
thanks for your interest..
signature...
|
|
|
|
|
1 & 2 depend on which type of barcode you're trying to create. I'm guessing you're trying to create an EAN barcode given you specify a country code?
You should probably get a copy of Roger Palmer's book if you need more info http://www.paltec.ca/Book.htm[^]
3 - Sorry, I don't understand.
Me: Can you see the "up" arrow?
User:Errr...ummm....no.
Me: Can you see an arrow that points upwards?
User: Oh yes, I see it now!
-Excerpt from a support call taken by me, 08/31/2007
|
|
|
|
|
yes, i am try to code ean13. I will do this for a small shop. which type of barcode do you suggest me? ean8 is appropriate for this stuation?
forthermore, what is you suggestion to solve odd and even numbers.
signature...
|
|
|
|
|
The business I work for uses code39 for most barcodes.
We can read ean however code39 is definitely the easiest to create.
What you will need is the code39 font which is freely available - search on google.
The beauty of code39 is that the only requirement is:
Starts and ends with an asterisk *
Everything between the asterisks is in caps.
For instance if one of our products is bic01 what we do is code it as *BIC01* and simply change the font to code39.
Any barcode reader that can read code 39 will then be able to read this and the code returned will be BIC01.
IN this manner just install the font on the users computer and ensure that your code uses that font.
The disadvantage of ean is that strictly speaking you need to purchase a subset of these barcodes to make sure that no duplicates exists - from experience I can tell you that duplicates do exist.
Trying to create your own barcodes by drawing black lines is asking for trouble - you are much better off buying an ean font(if that is what you really want) than trying to design one - it will cost you much less, in terms of money and bug fixing, in the long term .
You always pass failure on the way to success.
|
|
|
|
|
thanks for your helps.
signature...
|
|
|
|
|