|
I'm having an issue with C# string literals. I'm trying to include double quotes in the string for a sql text. I've followed all the advice as to use either the backslash or "double double" quotes, but when I check the resulting output in the command window during debug, I get the backslahes showing up in the string.
code:
(backslash)
string s ="select ld_part, ld_lot, ld__dte01, ld_ref, ld_qty_oh, pt_um, (ld_qty_oh / (ld__dec01 * .012)) when pt_um = \"MS\" from ld_det, pt_mstr where ld_part like \"" + spec + "\" and pt_part = ld_part and ld__Dec01 > 0 and ld_ref= \"\" order by ld__dec01, ld__dte01";
(@ sign and double doubles)
string s = @"select ld_part, ld_lot, ld__dte01, ld_ref, ld_qty_oh, pt_um, (ld_qty_oh / (ld__dec01 * .012)) when pt_um = ""MS"" from ld_det, pt_mstr where ld_part like """ +spec+ @""" and pt_part = ld_part and ld__Dec01 > 0 and ld_ref= """" order by ld__dec01, ld__dte01";
output in command window(either way):
?sql
"select ld_part, ld_lot, ld__dte01, ld_ref, ld_qty_oh, pt_um, (ld_qty_oh / (ld__dec01 * .012)) when pt_um = \"MS\" from ld_det, pt_mstr where ld_part like \"12406%\" and pt_part = ld_part and ld__Dec01 > 0 and ld_ref= \"\" order by ld__dec01, ld__dte01"
desired result:
"select ld_part, ld_lot, ld__dte01, ld_ref, ld_qty_oh, pt_um, (ld_qty_oh / (ld__dec01 * .012)) when pt_um = "MS" from ld_det, pt_mstr where ld_part like "12406%" and pt_part = ld_part and ld__Dec01 > 0 and ld_ref= "" order by ld__dec01, ld__dte01"
Any ideas?
thanks!
Bill Polewchak
Technical Design Lead
Software Development/Architecture
Avery Dennison Corp.
|
|
|
|
|
Both of your examples will produce the same string. The debug window shows the backslashes because it is intended to display "special" characters in that way. When the string is sent to the database, the characters will be expressed as intended, not parsed for display. I don't know what kind of database you're using, but what you have should work in Access.
You might consider sidestepping the whole issue and using single quotes - I think they'll work in Access, and they're required by most other DB platforms instead of double quotes.
One other note: You might want to also consider using parameterized queries instead of putting everything into a single string. I don't know where the value for "spec" comes from, but if it is in any way visible to users, you're opening yourself to SQL injection attack. Also, parameterized queries can often be cached by the DB platform, improving performance.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Thanks for promptly confirming my hopes! I was wondering whether or not this is a display issue in the command window.
Since this is being used in an oledb (ODBC.NET) object query to a Progress database in our ERP system, I needed to use the double quotes. The resident application db is SQL Server 2000, so in that case, I could have used single quotes, or as I'm more used to doing, using a SQLOLEDB command object to call a parameterized sp!!!
I actually had to do a bit of research to use this old school text method
Thanks again.
cheers,
Bill Polewchak
Team Leader
Software Development/Architecture
Avery Dennison Corp.
|
|
|
|
|
Hello,
I have a database application in my connection string l have the following.
OleDbConnection cnnTeacher = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Library\LibrarySystem.mdb;Persist Security Info=False");
But if want to install this program on another machine l don't want to have to change every connection string. Is there an easy way to do this.
The database is in the same folder that the solution is in.
Thanks in advance,
Steve
|
|
|
|
|
You could create a config (app.config or web.config depending on your project type) file for your application and expose the connection information there as separate variables (e.g. Provider, Data Source, Persist Security Info etc.) See the System.Configuration namespace for information about accessing the contents of config files (or check out the CMAB [Configuration Management Application Block] provided by MS).
This approach is favorable to hard coding the connection information for a number of reasons:
1. You, the developer, are free to change your database platform easily in your development environment.
2. Users of your application can place their datastore where they choose.
3. Changes may be made at any time, and will take effect immediately, and without requiring a recompile.
4. You can encrypt the authentication info in a config file if necessary.
Note: You may also want to include parameters for accessing secured Access databases. Even if you don't lock down the DB currently, you may want to in the future.
Alternate choices to using a config file include using the registry, or a text file.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hello,
I managed to find a solution that worked. I placed the database where the exe file is, and used the Application.StartupPath to get the full path to where the database is.
Is that a good way to solve this problem when you create an installer, to be installed on another machines?
OleDbConnection cnnLogin = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Application.StartupPath + @"\LibrarySystem.mdb;Persist Security Info=False");
Many thanks in advance,
Steve
|
|
|
|
|
Hi,
I have a user control that includes two other controls, one is a Panel and the other a TextBox (or actually, a user control inherited from a TextBox). The Panel can be used for mouse input (the position of a mouseclick and so on) and the TextBox is there for numerical input. What I want to achieve is that the user can type in a number in the TextBox without having to explicitly give focus to the TextBox first. Preferably, I'd like the TextBox to be filled without ever recieving the focus. I've been able to redirect the key input through the OnKeyDown and OnKeyUp of the user control to those of the TextBox, but it doesn't seem to get processed when the TextBox doesn't have the focus. What I'm desperately trying to prevent is having to catch and interpret every key high-up, for instance in ProcessCmdKey, and then set the text in the TextBox myself. What you're doing then is essentially rebuilding the functionality of a TextBox, which doesn't seem like a good idea.
So I though a good compromise would be to let the user control 'listen' for any key input and take that as a sign that the user wants to use the TextBox. Upon the first encountered key I give the focus to the TextBox and redirect all key input to it. Unfortunately, when the very first key reaches the TextBox, it DOES have the focus but the key still isn't shown. Although the Focused-property of the TextBox is true, somehow it doesn't seem to realise this yet deep down. Calling the TextBox' OnKeyDown twice doesn't help. Only the second key I press gets displayed.
Does anyone know why this occurs or how to circumvent it? Or perhaps someone has an entirely different approach to achieve the effect I'm aiming for, basically a TextBox that can take raw keyboard input but that doesn't need focus.
Thanks.
|
|
|
|
|
I'm a newbie. So please be patient. I'm working on a C# app in compact framework for a PDA. It connects to a device and extracts and updates data. I need to double check with the user before I continue with the update. I would normally use a MessageBox with an OkCancelButton. However, the compact framework doesn't support but one overload: MessageBox(string). I need to send confirmation (bool) back to the form and act accordingly with the update. Could someone please head me in the right direction.
Thanks in advance for any and all help.
|
|
|
|
|
Actually, the Compact Framework support 3 overloads of MessageBox.Show. The one your looking for supports which buttons to dispaly and also returns which button was clicked. Look here[^] for the documentation on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Right you are. The compiler was telling me that there were no such overloads because I had them in the wrong sequence.
Thanks a bunch for the help.
|
|
|
|
|
Dear forum:
I've stored .rtf file content into my MS-SQL DB using Image DataType.
Now I have problem to read & show it in a RichTextBox!
First I Fill my DataSet using a DataAdapter & use following code to show it
Byte[] Txt = (Byte[]) dataSet11.LetterSel.Rows[0]["Content"];<br />
MemoryStream ms = new MemoryStream();<br />
ms.Write(Txt, 0, (int)Txt.Length);<br />
richTextBox1.LoadFile(ms, RichTextBoxStreamType.RichText);<br />
ms.Close();
but it has been useless yet! & giles "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection." error
Please help me in the last step of my App.
Look to hear from u ASAP.
Always ,
Hovik Melkomian.
|
|
|
|
|
|
Dear leppie:
Tnx for ur reply, but I tried it before! & didnt solve it. of course now it give another error "Invalid file format."
actually when I open a .RTF file & push it to my buffer, displaying it in RichTextBox has no problem, but when I store it in DB & read it from stored Data to show in RichTextBox gives me that error!
my code is lie belove:
string file = openFileDialog1.FileName;<br />
FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read);<br />
<br />
richTextBox1.LoadFile(stream, RichTextBoxStreamType.RichText);<br />
<br />
byte[] buffer = new byte[stream.Length];<br />
stream.Read(buffer, 0, (int)stream.Length);<br />
stream.Close();<br />
<br />
DataRow TxtRow;<br />
TxtRow = dataSet11.LetterSel.NewRow();<br />
TxtRow["Number"] = 1;<br />
PicRow["Content"] = buffer;<br />
dataSet11.LetterSel.Rows.Add(TxtRow);<br />
AdapterLetter.Update(dataSet11, "Letter");<br />
buffer = null;<br />
<br />
dataSet11.Letter.Clear();<br />
AdapterLetter.SelectCommand.Parameters["Number"].Value = 1;<br />
AdapterLetter.Fill(dataSet11, "Letter");<br />
<br />
Byte[] Txt = (Byte[]) dataSet11.Letter.Rows[0]["Content"];<br />
MemoryStream ms = new MemoryStream();<br />
ms.Write(Txt, 0, (int)Txt.Length);<br />
ms.Seek(0, SeekOrigin.Begin);<br />
<br />
<big>richTextBox1.LoadFile(ms, RichTextBoxStreamType.RichText);</big><br />
ms.Close();
any idea?!
Always ,
Hovik Melkomian.
|
|
|
|
|
|
if u mean removing ms.Close(); it was useless! by the way the problem is when I wanna set the RichTextBox content by RichTextBox.LoadFile method witch is before closing memory stream! & LoadFile gives error!
but when I use a fileStream it has no error! How can I write my MemoryStream in a fileStream (make a temp file) & then show its content in RichTextBox?!
of course its a bit dummy!
Always ,
Hovik Melkomian.
|
|
|
|
|
Hovik Melkomian wrote:
but when I use a fileStream it has no error!
maybe try .Flush() after write, i cant think of any reason it should not work. As a last resor, so the content both to a filestream directly and another via memory but also save to file, this way you can just run the file thru a diffviewer and see what is different.
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
Dear leppie:
After some debuging & ... I got that my reading is OK, so when I was checking my save operation I saw that I didnt set my Stream position to 0! & so the buffer was full of empty chars & ...
now its ok & I really enjoynig my Paperless Application
That was ur idea (position) & tnx for ur idea & ur time!;)
Always ,
Hovik Melkomian.
|
|
|
|
|
what is the difference between a library and a DLL?
What is a wrapper?
|
|
|
|
|
Libraries are places people got to check out books or read periodicals...
Just kidding. In the context of software development, "library" usually implies the same thing as "DLL", in fact "DLL" stands for "Dynamic Link Library" or just "library".
"Library" can also refer to a collection of components (DLLs) that together form a reference source for an area of functionality, as in term "Control Library".
A wrapper is a class or group of classes that abstract the functionality of another component or group of components, making them easier to work with.
For instance, automating MS Office 2003 with C# is neither fun nor quick, because the automation API for Office is COM-based, and often provides for very broad usage interpretation in its method calls by employing optional arguments. To automate Word, for instance, using C#, there is at least one required wrapper - the interop wrapper or "RCW" (runtime-callable wrapper) that allows managed code to see and use the Word automation type libraries. You may have seen or heard of the Office Primary Interop Assemblies? That's what those are; RCWs customized and provided by Microsoft.
In my experience with Office automation, I've learned that a second wrapper is often beneficial, just to simplify calls. As I've said, the method signatures in the Office automation classes are often VERY long (many arguments). In VB 6, that was no problem, since many of the arguments were optional and could be omitted for the most part. In C# however, that's not an option, so every argument must be provided, every time a call is made...tedious. So I have a sizable and growing library that "wraps" many of the methods in the Office API, just to make calling them simpler.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
has anyone come across an application like Irfanview ( www.irfanview.com) which allows u to view multiple image formats and convert between them
|
|
|
|
|
ive come across many applications which the datagrid houses many controls like comboboxex...icons...checkboxes...etc! how is this done? If any third party controls are used, could u let me know about a few of them?
|
|
|
|
|
There are a couple of ways to get the effect you're referring to:
1. Manually configure the columns in the datagrid using the grid's property builder in the design view - this offers a variety of controls other than strictly data bound columns, such as edit, save and delete buttons.
2. Use template columns. Template columns provide a miniature design surface to lay out the controls for datagrid columns by just dragging them from the toolbox.
3. Custom control(s).
A full set of instructions or a code sample would be prohibitively long for publication here, but there is an okay discussion of methods 1 and 2 above in the online help, and many (often better) examples here on CodeProject if you do a search on DataGrid or Template Column.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hello,
There are a few articles on CP about in-place editing of ListViews and DataGrids.
This one[^]is a very good example and is easy to use. You can use any control that you want to edit a subitem of you grid or list view.
Hope this helps!
Hugo Migneron
|
|
|
|
|
I am calling an application DLL with webservices in the interface the InterNet Explorer and when use the following instruction for call of an item of the menu:
Form _ Form = new Forms.frmcadInspeto();
_ Form.Show();
This opens the Form Window normally in explorer, but why I do not obtain to sail with keyboard key TAB in the Textbox controls, Combox, etc, being that to use the following expression the navigation of the TAB occurs:
_ Form.ShowDialog();
It will be that it has a BuG with the method show for interface the explorer?
|
|
|
|
|
I have an array of picture box (the pictures box are in a windows form).
I push on a picture box, an my application make something in relation the picture pressed. My problem is this:
how can I know, which picture has been pressed?
I tried this way:
this function need when some picture has been pressed.
private void MyImage()
{
for (int j=0; j
|
|
|
|
|