|
This forum is for C# programming questions.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
hi, i am a vb.net user and i want to try to convert my vb.net program to C#.Net. i have a class (clsDataAccess) where i execute my query. i'd try it to convert it to C#.Net but it gives me a lot of errors. i want to use this clsDataAccess as my default class when executing my query. can you pls help me to convert it. below is my code.
Imports System<br />
Imports System.Data<br />
Imports System.Data.SqlClient<br />
Imports AddressBook.usermod1<br />
<br />
Public Class clsDataAccess<br />
<br />
Public objConnection As SqlConnection<br />
Public objTransaction As SqlTransaction<br />
<br />
Public Function SqlConnect() As Boolean<br />
<br />
Try<br />
objConnection = New SqlConnection<br />
'objConnection.ConnectionString = "Server=(local);database=AddressBook;user id=sa;password=;"<br />
objConnection.ConnectionString = "Server=" & GetServer("\conn.cfg") & "; DataBase=" & GetDatabase("\conn.cfg") & "; User ID =" & GetUser("\conn.cfg") & "; Integrated Security=false"<br />
<br />
If objConnection.State = ConnectionState.Closed Then _<br />
objConnection.Open()<br />
<br />
Return True<br />
<br />
Catch ex As Exception<br />
<br />
MsgBox("Failed to connect to data source.", MsgBoxStyle.Information, "")<br />
Return False<br />
<br />
Finally<br />
objConnection.Close()<br />
<br />
End Try<br />
<br />
End Function<br />
<br />
Public Function ExecuteQuery(ByVal strSQL As String) As DataTable<br />
Dim objDataTable As DataTable<br />
Dim objDataAdapter As SqlDataAdapter<br />
<br />
Try<br />
<br />
SqlConnect()<br />
objDataAdapter = New SqlDataAdapter<br />
<br />
With objDataAdapter<br />
<br />
objDataTable = New DataTable<br />
.SelectCommand() = New SqlCommand(strSQL, objConnection, objTransaction)<br />
.Fill(objDataTable)<br />
<br />
Return objDataTable<br />
<br />
End With<br />
<br />
Catch sqlex As Exception<br />
Throw sqlex<br />
<br />
Catch ex As Runtime.InteropServices.COMException<br />
Throw ex<br />
Finally<br />
objDataAdapter = Nothing<br />
<br />
End Try<br />
End Function<br />
<br />
Public Sub ExecuteNonQuery(ByVal strSQL As String)<br />
Dim objSqlCommand As SqlCommand<br />
<br />
Try<br />
SqlConnect()<br />
objSqlCommand = New SqlCommand(strSQL, objConnection)<br />
objSqlCommand.Connection.Open()<br />
objSqlCommand.ExecuteNonQuery()<br />
<br />
Catch ex As SqlException<br />
Throw ex<br />
<br />
Catch ex As Runtime.InteropServices.COMException<br />
Throw ex<br />
<br />
Finally<br />
objSqlCommand = Nothing<br />
<br />
End Try<br />
End Sub<br />
<br />
Public Function ExecuteNonQuery(ByVal strSQL As String, ByVal sqlparams As SqlParameter()) As Boolean<br />
<br />
Try<br />
Dim intindex As Integer<br />
Dim objsqlcommand As New SqlCommand(strSQL, objConnection, objTransaction)<br />
<br />
For intindex = 0 To UBound(sqlparams)<br />
objsqlcommand.Parameters.Add(sqlparams(intindex))<br />
Next<br />
<br />
objsqlcommand.ExecuteNonQuery()<br />
Return True<br />
<br />
Catch ex As Exception<br />
<br />
Throw ex<br />
<br />
End Try<br />
End Function<br />
End Class
Thank You.
Don't block the drive way of all the newbies in programming.
|
|
|
|
|
looks like ur trying to convert a VB class to C#
hope that link helps you
Convert VB .NET to C#[^]
Rocky
Success is a ladder which you can't climb with your hands in your pockets.
|
|
|
|
|
This seems lazy to me. I would have thought it would be a good introduction to C#, converting existing code.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
I have a BenQ x700 Pro keyboard and I installed Windows Vista. Unfortunetly BenQ does not want to make software for my model. It has specialty keys such as: Volume Control, Mute, Standby, My Media (loads Windows Media Player), Next Track, Previous track, Play/Pause and Stop just to name a few. Is it possible to catch these specialy keys? If so do you have any suggestions how to do this?
[Edit]
The program has to be able to catch keys wether or not it has focus.
[/Edit]
Thanks.
modified on Wednesday, January 30, 2008 4:29:19 PM
|
|
|
|
|
A bit of googling suggests that the driver itself handles the extra keys so the chances are Windows won't even see them as keystrokes without a working driver. Have you tried installing the XP drivers using XP compatability mode?
Failing that, this[^] page (BenQ Singapore) has a driver dated December 2007 so it may work with Vista. It's in .rar format so you'll need WinRar or something similar (there are free utilities available) to unzip it.
Good luck!
|
|
|
|
|
Yes I tried BenQ software for XP and it didn't work. It caught the actions but nothing happened as a result. IE I turned the volumn control knob on the keyboard but the volume didn't change.
I tried the site the Singapore site but it didn't work. Thanks anyways.
|
|
|
|
|
A global key hook should be able to catch the keys. A quick search revealed this[^].
You will be looking for the following values from the Keys[^] enumeration:
MediaNextTrack - The media next track key (Windows 2000 or later).
MediaPlayPause - The media play pause key (Windows 2000 or later).
MediaPreviousTrack - The media previous track key (Windows 2000 or later).
MediaStop - The media Stop key (Windows 2000 or later).
VolumeDown - The volume down key (Windows 2000 or later).
VolumeMute - The volume mute key (Windows 2000 or later).
VolumeUp - The volume up key (Windows 2000 or later).
Then you could use the MCI[^] API to forward the commands.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Regarding that code you pointed me too. After put each line of code on it's one physical line and after fixing a few problems I have one left to solve:
<br />
protected static extern IntPtr SetWindowsHookEx(HookType code, HookProc func, IntPtr hInstance, int threadID); <br />
Error #1:
The type or namespace name 'HookProc' could not be found (are you missing a using directive or an assembly reference?)
On a slightly related note. Can someone explain to me what:
[DllImport("user32.dll")]
does?
|
|
|
|
|
IIRC HookProc is a function pointer to the code that you want to have run everytime a key is pressed.
DllImport is used to make a native dll's functions available within a managed application.
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop.
-- Matthew Faithfull
|
|
|
|
|
[Starts Laughing Uncontrollably]
Even thought BenQ's software is not installed a majority of the specialty buttons work such as Media Player control, Volume control, and the nav forwards and backwards buttons.
Thanks for the help.
|
|
|
|
|
I have a Panel with the Docking code:
Panel.Dock = DockStyle.Left;
And I have another panel with the same code, but I can't get the other panel underneath the already docked Panel.
How can I solve this?
|
|
|
|
|
What do you mean underneath? Do you want the two panels to form a single column with one on top and one on bottom?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Yes, it keeps making different columns but I want them, one on top, one on bottom.
|
|
|
|
|
In that case you need to nest the panels.
The idea is you have your MainForm with a panel (say leftPanel) docked to the left. Now, you would add two panels to leftPanel. The first would be docked to the top and the second would be set to Fill.
If you want something that is user-customizable (like Visual Studio) then that's a different story. There are examples of this if this is what you are looking for.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Thankyou, I only wanted a simple docking network thanks ^_^
|
|
|
|
|
Hi, I have a class I want to deserialize using the BinaryFormatter 's Deserialize method. I never really had any problem with this but for some reason I'm now getting a very weird exception: The complaint is that the constructor of this particular class is missing, while I've obviously implemented it. This is what my code looks like:
[Serializable]
public class IndexedBaseDataCollection : Dictionary<int, IBaseDataContainer>, IBaseDataContainer
{
public IndexedBaseDataCollection()
{
}
.
.
}
And here's the exception I'm getting:
<br />
System.Runtime.Serialization.SerializationException: The constructor to deserialize an object of type 'Engineer.Data.IndexedBaseDataCollection' was not found. ---> System.Runtime.Serialization.SerializationException: The constructor to deserialize an object of type 'Engineer.Data.IndexedBaseDataCollection' was not found.<br />
at System.Runtime.Serialization.ObjectManager.GetConstructor(Type t, Type[] ctorParams)<br />
at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)
I've tried using a construct that overrides the base() constructor but that doesn't seem to help at all. I can only guess this might have something to do with the Dictionary base class. All values of type IBaseDataContainer are perfectly serializable by the way. Any ideas?
Thans in advance.
Standards are great! Everybody should have one!
|
|
|
|
|
I bet that it is due to the fact that dictionary is only serializable due to the fact that it implements the ISerializable interface. I think the deserializer is looking for the deserialization constructor within your type, which clearly doesn't exist. Perhaps you will need to create a constructor that matches the one that is implemented with the ISerializable interface and simply pass it through to the base as follows:
protected IndexedBaseDataCollection(SerializationInfo info, StreamingContext context)
: base(info, context) {
} If that doesn't work, then you may even need to implement the full ISerializable interface, and pass the data through to the dictionary. This is just a guess, but hopefully it is helpful. Let us know if you get it working,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
This is exactly right. Thanks!
Standards are great! Everybody should have one!
|
|
|
|
|
|
I think you need to add a special constructor for deserialization like so:
protected IndexedBaseDataCollection(SerializationInfo info, StreamingContext context) {
}
The Dictionary<TKey,TValue> (in .Net 3.x anyway) implements ISerializable. Which (I'm 99% sure) means you need the above constructor for deserialization.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi,
Anyone any idea how i can get the selected style from windows XP. (classic or XP style ?)
thx
kurt
|
|
|
|
|
Great,
declaration.
[DllImport("uxtheme", ExactSpelling=true, CharSet=CharSet.Unicode)]<br />
public extern static Int32 GetCurrentThemeName(StringBuilder stringThemeName, int lengthThemeName, StringBuilder stringColorName, int lengthColorName, StringBuilder stringSizeName, int lengthSizeName);<br />
and the way to use
StringBuilder stringThemeName = new StringBuilder(260);<br />
int lengthThemeName = 260;<br />
StringBuilder stringColorName = new StringBuilder(260);<br />
int lengthColorName = 260;<br />
StringBuilder stringSizeName = new StringBuilder(260);<br />
int lengthSizeName = 260;<br />
if(GetCurrentThemeName(stringThemeName, lengthThemeName, stringColorName, lengthColorName, stringSizeName, lengthSizeName) == 0)<br />
{
Greetz
Kurt
|
|
|
|
|
I´m starting to build a windows wizard program using visual studio 2005. And I would like to know what’s the best way to do it.
I’m trying to use a different usercontrol for each scenario but I don’t know if it’s the better solution..
|
|
|
|
|