|
Dim loConn, lsSQL, loRs
Set loConn = CreateObject("ADODB.Connection")
' Open a connection to the database
loConn.Open("DSN=myDSN;UID=something;PWD=Something;")
' Insert a new record into the table
lsSQL = "SET NOCOUNT ON;" &_
"INSERT INTO tMembers (MemberName) VALUES ('Manohar');" &_
"SELECT @@IDENTITY AS NewID;"
' Execute the SQL statement
Set loRs = loConn.Execute(lsSQL)
' Get the inserted ID
llID = loRs.Fields("NewID").value
' Close the connection
loConn.Close()
Set loConn = Nothing
Hi guys,
What would be the equivalent code of the the above in C#? I have used ADO.NET a bit. How would i have to access the returend value (NewID). Would i have to pouplate a dataset or something? Is there a simple way to access single values returned by a database such as
SELECT DISTINCT store_name FROM Store_Information WHERE id = 5
Thanks!
|
|
|
|
|
The SQL would stay essentially the same in ADO.net.
Use an OledbCommand (or SqlCommand if using SQL Server) and do MyReader = mYcommand.ExecuteReader();
A datareader is analogous to a forward-only ADO recordset. I your examles above, you are reutuning recorsets that just happen to have only one row, one column. A datareader would do the same.
|
|
|
|
|
hello all,
I want Compress a folder that contain some files and subfolders.
how can i do it in visual C#.Net
-- modified at 6:36 Sunday 1st October, 2006
|
|
|
|
|
|
See here[^] maybe its some helpful for you
|
|
|
|
|
hi,
I want to use timer in my service ,but the timer never starts although i have put the start code of the timer in the onstart() method of the service.
|
|
|
|
|
I guess you're using the System.Windows.Forms.Timer . This one won't work as your service has no message pump. Try the System.Timers.Timer or System.Threading.Timer .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hello.
I want to make an array of several controls for example buttons in my windows application.
is that possible in VS 2005?
Thanks everyone.
Please, Send me an answers to t_nedelchev@abv.bg.
t_nedelchev@abv.bg
|
|
|
|
|
Sure you can. Simply declare the array and assign a new or existing Button reference to it.
Button[] buttonarray = new Button[5];
for (int i = 0; i < buttonarray.Length; i++)
buttonarray[i] = new Button(); If you create the buttons dynamically don't forget to add them to the controls collection of your form or any container in it, so they get displayed.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thanks for your fast reply, Stefan.
I wrote the code above.
this creates buttons, but they are invisible.
after your piece of code i wrote the following:
buttonarray.Location =...
buttonarray.size = ....
buttonarray.name = ...
buttonarray.tabindex = ...
buttonarray.text = ....
buttonarray.visible = ...
but again without success - there no buttons on my form.
what do i miss?
thanks.
|
|
|
|
|
As I said you have to add them to the controls collection of your form or any container in it. After all buttons are created, add the following line:
this.Controls.AddRange(buttonarray);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Dear Stefan Troschütz, Thanks a lot. I made it.
|
|
|
|
|
hi i am try learn "push buttons events" & i stack on this.
i want on key ENETER push navigate on my pooor webBrowser
but this doesn work
1)
void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
// Navigate if the ENTER key is pressed
if (e.KeyChar == '\r')
Navigate();
}
2)
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if(e.Alt && e.KeyCode == Keys.E)
}
please tell me where prolem?
i am using VC#2005
tnx for help
i am noob in c#
|
|
|
|
|
At first I'm not really sure whether the keychar resulting from pressing enter is "\r". It would be better to check for it inside the KeyDown event handler e.KeyCode == Keys.Enter . This way you will also have your keyboard event handling in one place.
Secondly, are you sure the events are really fired (You may debug it)? Most probably your entering text in some other control, so the keyboard events of your form are only fired, if you set KeyPreview true. Either do this, or much better IMO register the KeyDown event handler to the control that's getting edited.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
i am type this
void Form1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
this.webBrowser1.Navigate(this.toolStripTextBox1.Text);
}
0 errors 0 warnings
& nothink hepend
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
Athlon 64 3500+, Gigabyte GA-K8NXP-9, 2x512 DDR400 Kingston, Inno3d 6200 PCIe, SS2 B2C2 v2.6, HDD := 450gb, Genius 56k int, NEC DVD-RW и мать его Суньмастер 550.
|
|
|
|
|
As I said, if you're entering text in some other control (probably the toolStripTextBox1), the keyboard events of your form aren't fired unless you set the KeyPreview property true . So either do this, or much better IMO register the KeyDown event handler to the control that's getting edited (toolStripTextBox1) cause otherwise Navigate will be executed whenever you're pressing enter.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
all what i done its
private void Form1_KeyDown(object sender,KeyEventArgs e)
{
if(e.KeyCode== Keys.Enter)
this.webBrowser1.Navigate(this.toolStripTextBox1.Text);
}
then just swith in properties of textbox
http://b.foto.radikal.ru/0610/87852a0cf72a.gif
& all work thx a lot
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
Athlon 64 3500+, Gigabyte GA-K8NXP-9, 2x512 DDR400 Kingston, Inno3d 6200 PCIe, SS2 B2C2 v2.6, HDD := 450gb, Genius 56k int, NEC DVD-RW и мать его Суньмастер 550.
|
|
|
|
|
If the KeyDown event handler is now registered to the ToolStripTextBox you should rename, so its obvious which KeyDown event it handles.
private void ToolStripTextBox1_KeyDown(object sender,KeyEventArgs e)
Also it would be a good idea to give the ToolStripTextBox a more descriptive name e.g. "toolStripTextBoxUrl".
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hello, everyone.
I make a program, which uses Serial port (COM1).
I'm working with VS 2005.
My problem is:
Is there any way or method to find out, if the COM1 port is already used from another application before i start my program?
Thanks a lot.
Please answer me to
t_nedelchev@abv.bg
t_nedelchev@abv.bg
|
|
|
|
|
AFAIK there's no other way than trying to open the serial port.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Im making a WinForm GUI for a program that run in the command shell. The problem is that shell program has problems if the input arguments have spaces because after each space it thinks its a new argument. For example:
abc.exe D:\My Documents\myfile.xml
will give an error like Error: invalid command line argument: 'D:\My'
It will work if i use:
abc.exe D:\MyDocu~1\myfile.xml ok
So my question is that how can i get the old style "MyDocu~1" or from an OpenFileDialog.FileName that has "D:\My Documents\myfile.xml". I dont know the name of the style so i called it "old style"
The shell program has an output argument that will send the resulting file to that directory but i will have the same problem as the input file. I just may have to use the OpenFileDialog with File.Copy to copy the file to my program's directory and move with File.Move the resulting file to the same directory as the input file using the file path from the OpenFileDialog.
modified 16-May-21 21:01pm.
|
|
|
|
|
I'm not sure whether the so calles old style is the proper way to deal with white spaces. If I recall right its purpose was to deal with names consisting of more than 8 characters. From what In know you deal with white spaces by putting the path between double quotes:
abc.exe "D:\My Documents\myfile.xml"
Try if your shell program recognizes the file this way and if so simply prepend and append a double quote character to the OpenFileDialog.FileName.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Wrap your path in double quotes and it should work
abc.exe "D:\My Documents\myfile.xml"
|
|
|
|
|
Hi, I have two datagridviews A and B. I want to set the bindingsource filter of datagrid B with the "Selected Row" of datagrid A. E.g. The customer name is in A, and the corresponding orders of that customer will show up in B.
Usually this would be done with the following code if I was using a ComboBox for A:
this.myBindingSource.Filter = "Name=" + myComboBox.SelectedValue;
But for a datagrid view all i can get is "myGridViewA.SelectedRows". How do I extract the selected row and the corresponding column value (Name) from SelectedRows?
A even better method would be how would this be done if Multi select is turned in datagridview A?
|
|
|
|
|
Just googling your question returned answers to your question. Try this site.[^]
A word of warning, I do not think you can have a master/slave relationship with multi select. But you can find out by trying.
|
|
|
|