|
Hi! I want to select only 10 rows from a dataTable each time, just as from a database("SELECT TOP 10 FROM orders WHERE ID <100 ORDER BY ID"). for example:
DataTable myTable = new DataTable("orders");
DataRow[] rows = myTable.Select("TOP 10 ID < 100");
1)How can I write the correct statement.
2)Can I ues "TOP" key word or there's other way to do it?
Thank you very much.
|
|
|
|
|
I'm kinda new to this but this is how i did it.
SqlCommand cmd = new SqlCommand(("SELECT TOP 10 FROM orders WHERE ID <100 ORDER BY ID",SQLConn);
cmd.CommandType = CommandType.Text;
SqlDataReader SQLData = cmd.ExecuteReader();
DataTable My_DataTable = SQLData.GetSchemaTable();
int iColumns = My_DataTable.Rows.Count; //shuld be 10
while(SQLData.Read())
{
string sOut = "";
for(int i=0; i
|
|
|
|
|
After I posted this message I keep searching the net and I find the solution to my problem.
The problem was caused by McAfee VirusScan Enterprise 8.0i's Buffer overflow protection.
I tried to disable it and my comboboxes start working well again.
If someone has the same problem read the document in
this location
|
|
|
|
|
In C or C++ we used to be able to call functions from DLL's by loading the dll library (Ex: LoadLibrary("library.dll");) then using the method GetProcAddress("functionName") to find a function by name in the library.dll.
Now in C# the Dll's contain classes rather than isolated functions.
Is is possible to call functions from Dll's in c#?
I am mainly interested in being able to pass a function name as parameter then use something like the GetProcAddress method that uses that function name to find it in the dll so we can call it.
Example in C++:
//this method will call a function from the library (no error checks to simplify)
void CallFunction(char* libraryName, char* functionName)
{
//declare the function that will be called:
typedef void * (FUNC)(int); //function that returns void and takes an int
FUNC pFunction;
//load dll library:
HINSTANCE hLibrary = LoadLibrary("Library.dll");
//find function in library:
pFunction = (FUNC) GetProcAddress(hLibrary, functionName);
//call function
pFunction(35);
}
|
|
|
|
|
|
|
SqlCommand cmd = null;<br />
<br />
cmd = connDB.CreateCommand();<br />
cmd.CommandText = "INSERT INTO MandantMC (" +<br />
"Mand, " +<br />
"MID, " +<br />
"VALUES " +<br />
"(?,?)";<br />
<br />
cmd.Parameters.Add("Mand", txtBoxMandant.Text.ToString());<br />
cmd.Parameters.Add("MID", txtBoxKürzel.Text.ToString());<br />
<br />
<br />
cmd.ExecuteNonQuery();
The connDB works. But this code does not. I try to get data from textboxes to SQL DB. If I make hardcoded code like :
... VALUES ('W','Y') then it works. But if I want data from controls, there is an error while passing cmd.ExcecuteNonQuery(). Also if I insert the ' ( within an own string ) it doesn't work. Only ' works in CommandText.
Any sols ?
|
|
|
|
|
The SqlClient uses named parameters, so you need to use @Mand and @MID instead of the ?'s in your sql string. In addition, you may need to specify @ when adding the parameters.
my blog
|
|
|
|
|
Yes, you do need to specify "@" before the parameter names when adding them to the SqlCommand.Parameters collection property.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
SqlCommand cmd = null;
cmd = connDB.CreateCommand();
cmd.CommandText = "INSERT INTO MandantMC (" +
"Mand, " +
"MID, " +
"VALUES " +
"(?,?)";
cmd.Parameters.Add(@"Mand", txtBoxMandant.Text.ToString());
cmd.Parameters.Add(@"MID", txtBoxKürzel.Text.ToString());
???
I tested it, still doesn't work.
Also placed it in CommandText and instead the ? with Parameter Names
|
|
|
|
|
You really should read the SqlParameter documentation. The solution is:
SqlCommand cmd = cmd.connDB.CreateCommand();
cmd.CommandText = @"INSERT INTO MandantMC (
Mand,
MID
VALUES (@Mand, @MID)";
cmd.Parameters.Add("@Mand", SqlDbType.NVarChar, 40).Value = txtBoxMandant.Text;
cmd.Parameters.Add("@MID", SqlDbType.NVarChar, 40).Value = txtBoxKürzel.Text; Notice the placement of "@". These are used for the parameter names. Replace "NVarChar" with whatever string type you defined in your SQL Server table and "40" with whatever length you defined for each column.
Also, why are you using Text.ToString() ? The Control.Text (inheritted by every derivative of Control like TextBox ) is already a string. You're wasting CPU time on unnecessary instructions.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thank you !
Remember my first code ?
Here the new CommandText
cmd.CommandText = @"INSERT INTO MandantMC (Mand,MID) VALUES (@Mand,@MID)";
Only 1 Line used. My last code doesn't work in multiple lines seperated by "+". Don't understand it...maybe compiler has problems with translating.
I never use toString on Textboxes. It was only for testing purpose while SQL Error occured. Also waste of typing
|
|
|
|
|
You shouldn't use string concatentation and "@" together. The literal character, "@", is so that you don't have to escape special characters (like backslashes) or so that your text can span multiple lines. Both your original code and my example of using "@" (but honestly, such a short SQL command is easier to read as a single line) would compile. Your only problem is that in the first code you posted you had a comma after MID which may cause a SqlException to be thrown; it's an extraneous comma.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am writing a c# windows application and want it to fill out a simple HTML form, submit the form, and return the content of the returned webpage. Is this possible?
I know how to use WebRequest and WebResponse to retrieve the content of a specific webpage, but I can not figure out how to retrieve the content of a webpage accessed by submitting a form.
Here's what the form looks like for some more info:
<html>
<form method=post action="../cgi-bin/homestead/mail.pl?mama172">
Name:
<input type="text" size="35" name="name">
Address?
input type="text" size="40" name="address">
City?
<input type="text" size="25" name="city">
<input type ="submit" value="Send">
</form>
</html>
|
|
|
|
|
Take a look at the HttpWebRequest.GetRequestStream[^] for HttpWebRequest.GetRequestStream which shows a good example of sending a POST request to a CGI sitting off on some web server.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
|
|
I have some code to open up a word document and add paragraph to the end of the document and then save and close the document. Now creating a word application object is fine, the opening a word document is fine. The problem occurs when I use this code
1. Word.Paragraph wordPara;
2. wordPara = wordDoc.Content.Paragraphs.Add(ref wordRng);
3. wordPara.Range.Text = "Original electronically authenticated by " + physName + " on " + strDateTime;
4. wordPara.Range.Font.Bold = 1;
5. wordPara.Range.InsertParagraphAfter();
For some reason after line 3 runs I recieve this error: "The server threw an excpetion". That is only error I recieve. In my project I am referencing the Microsoft Word 10.0 Object Library can anyone help?
Nicholas Ingratta
ningratt@hotmail.com
|
|
|
|
|
What else does the stack trace say for the exception? You should also try duplicating this code in a VBA project (the ol' school VB) which - if the .NET exception doesn't tell you enough, and I'm surprised that it doesn't - will give you more details about the problem itself through the Err object in VB (its implementation of IErrorInfo defined for OLE/COM).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
the only thing in the stack trace that is of any importance is:
"at Word.Range.set_Text(String prop)"
not really sure what that means
I only have Visual studio .net so I cannot create and old VBA project that I know of
|
|
|
|
|
Obviously you have Office (otherwise you couldn't even instantiate the WordApplication class), so you have VBA. VBA = "Visual Basic for Applications" and is a VB binding to the application's automation layer. Just click Tools->Macro->Visual Basic Editor.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
|
And it won't. VB != VB.NET. It's merely the same syntax. VB (6 and older) is an automation client that uses objects defined in type libraries and implemented by COM servers. VB.NET uses the .NET BCL (base class library) and compiles to Intermediate Language (IL).
So, you copied VB.NET code into a VB IDE (Integrated Development Environment). You need to write VB which is documented if, in the IDE, you click on the Help menu (and like Contents or Index or whatever).
The basic objects will be the same, but the types not defined in the typelib (like Missing.Value) will not work - they're defined in the .NET BCL and, unless exposed to COM through a CCW, cannot be called by VB6 (which is what the VB IDE in Office and other applications uses).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi!
I've a Web Service and 3 different SoapExtension. In my client app., I configure the web.config to execute the 3 diferent SoapExtension.
I'm trying to throw a SoapException in the first SoapExtension and i wan´t to stop the message flow. I don´t want that the flow of the Soap Message continue.
Is that possible?
|
|
|
|
|
Hi!
I am writing a server/client application in which I need to transfer short text strings across a network from the server to the client. The message receiver in the client is running in its own thread, and it uses a stream reader to get the message strings from the TcpClient.
It appears that both the 'Read' and 'ReadLine' methods of the StreamReader class blocks until there is something on the stream (if it is empty when they are invoked). The problem is that not even a call to .Abort() will interrupt the Read(Line) metod (which is exactly what I want to do). Is there any way to abort a call to Read(Line)?
I have tried to use the Peek() method to determie whether or not the stream is empty. However, Peek() returns -1 even though ReadLine() returns with a string that is supposed to be there. Any thoughts on why this happens?
Does anyone no of a construct that provides a non-blocking read from a stream?
|
|
|
|