|
the problem is in my webservice, but this is in C#, and the problem is more C# related.
the code below is the code i use, it always return false through the Catch, the Catch returns an error found in here[^] (the blue boxes are the absolute paths, you don't need them).
the problem i can't figure out, is why?
if someone can help me i would be very thankful.
yours, NaNg.
[WebMethod]<br />
public bool AddProject(string ProjName, string ProjID)<br />
{<br />
try<br />
{<br />
objCon.Open();<br />
DataSet ds = new DataSet();<br />
objDA = new OleDbDataAdapter(string.Format("Select Count([SID]) from tblProjects Where SPorjID = '{0}' And SProjName = '{1}'", ProjID, ProjName), objCon);<br />
123 -> objDA.Fill(ds, "tblProjects");<br />
if ((int)ds.Tables[0].Rows[0][0] == 0)<br />
{<br />
objCmd = new OleDbCommand(string.Format("Insert into tblProjects(SProjID, SProjName) Values('{0}', '{1}')", ProjID, ProjName), objCon);<br />
objCmd.ExecuteNonQuery();<br />
return true;<br />
}<br />
else<br />
return false;<br />
}<br />
catch (Exception exp)<br />
{<br />
return false;<br />
}<br />
finally<br />
{<br />
objCon.Close();<br />
}<br />
}
|
|
|
|
|
You either need to set the insert command's command text or you need to use parameters. Change your code to do this instead:
string selectCommand = "SELECT COUNT...";
objDA = new OleDbDataAdapter( selectCommand, connection );
objDA.InsertCommand.CommandText = string.Format("Insert into tblProjects(SProjID, SProjName) Values('{0}', '{1}')", ProjID, ProjName);
objDA.InsertCommand.ExecuteNonQuery();
Alternatively, you can use parameters like this:
string selectCommand = "SELECT COUNT...";
objDA = new OleDbDataAdapter( selectCommand, connection );
objDA.InsertCommand = new OleDbCommand( "Insert into tblProjects(SProjID, SProjName) Values( ?, ?)", connection );
objDA.InsertCommand.Parameters.Add( "@SProjID", OleDbType.VarChar, 30, "SProjID" ).Value = ProjID;
objDA.InsertCommand.Parameters.Add( "@SProjName", OleDbType.VarChar, 30, "SProjName" ).Value = ProjName;
objDA.InsertCommand.ExecuteNonQuery();
Hope that helps.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
hmmm... =\ both of them give me the same exception as before, nothing works and i don't know why =\
and i want to focus you, the problem is not in the insert command, but in the select command.
string.Format("Select Count([SID]) from tblProjects Where SPorjID = '{0}' And SProjName = '{1}'", ProjID, ProjName);
|
|
|
|
|
i'm sorry for mistaking you....
i found the problem and fixed it, i almost couldn't find it, i was wrong in the field name, between the r and the o... thanks alot
|
|
|
|
|
Glad you figured it out.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Hi All,
I need to create 2 list in my application.
I want to add Grid to each list ( to make easy the user to read the list ).
For example .... first list will hold all process that run in the machine that the other list will contain info about the process that the user will be focus on (on mouse click even the second list will be update).
My problem is
1.What object i need to use to get this grid list ?
2.I do i get the path of some process that run ? ( the path of the file of the process )
Thanks for any help.
-- modified at 9:50 Saturday 11th February, 2006
|
|
|
|
|
|
First, if you post a question in the forum, you better be patient waiting for an answer. We don't get paid to do this since The Code Project is entirely a volunteer effort. On top of that, you asked a question on the weekend!
To answer your first question, a ListView control will do everything you appear to be specifying, but in one control. It'll look just like the list in the Task Manager.
As for getting the path to the process, you need to get the MainModule of the Process, then you can use the FileName property of the module. Be prepared to handle some exceptions though. YOu can't get the Filename for the System or Idle processes.
For Each proc As Process In Process.GetProcesses()
Try
Debug.WriteLine(String.Format("{0} - {1}", proc.ProcessName, proc.MainModule.FileName))
Catch ex As Exception
Debug.WriteLine(String.Format("{0} - N/A", proc.ProcessName))
End Try
Next
Damn! Wrong forum again!! Here's the C# version:
foreach (Process proc in Process.GetProcesses())
{
try
{
Debug.WriteLine(string.Format("{0} - {1}", proc.ProcessName, proc.MainModule.FileName));
}
catch (Exception ex)
{
Debug.WriteLine(string.Format("{0} - N/A", proc.ProcessName));
}
}
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 16:52 Saturday 11th February, 2006
|
|
|
|
|
Hello gurus,
I'd like to know how I can browse all SQL servers over a enterprise network in C# in order to build the connection string. The user could select the SQL server on wich (s)he want to connect to like the "Browse for servers" dialog box from the "SQL Server Management Studio" does...
Can someone show me a code snippet for doing this?
Thanks in advance for the help.
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
You don't mention if you are using SQL Server 2000 or 2005. I'll assume 2000 because I can provide you with an answer (though I would be surprised if the answer was much different in 2005).
You need to use SQLDMO. This is a COM component that allows you to programmatically control SQL Server. Here is a basic snippet for loading a list of servers:
ArrayList serverList = new ArrayList();
SQLDMO.Application dmo = new SQLDMO.Application();
SQLDMO.NameList nameList;
nameList=dmo.ListAvailableSQLServers();
foreach ( object svrName in nameList)
{
string server = svrName.ToString();
if (server == "(local)")
{
server = "localhost" ;
}
serverList.Add ( server ) ;
}
The section where I check to see if the current server name is (local) and then change it to localhost is there because if you provide (local) in your connection string, it won't work properly. It expects localhost.
You can now use the ArrayList serverList in a listview or a combobox. In order to use SQLDMO, you will need to add a reference to it. Just right-click and "Add Reference" on the references folder in your project. Then click the COM tab in the ensuing dialog. Search through that list for "Microsoft SQLDMO Object Library". Click Select and then Ok. Visual studio will automatically make a .NET wrapper for the object and you should be able to use it as I have specified in my code above (though the SQLDMO namespace may come up as something different in yours. Just look at the references list once it's been added to know if you need to alter that in your code).
Let me know if you have any questions.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
When I wana to run this project http://www.codeproject.com/csharp/FTP/FTPCom.ZIP but it has a some errors
any one can run ?
|
|
|
|
|
Maybe you should try posting to the articles message board?
I did notice that it was developed using VS 2002 & .Net Framework 1.0, most people are now using v1.1 of the framework. Maybe this is the problem?
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
View my Blog
|
|
|
|
|
using System;
namespace MyClassNameDLL
{
///
/// Summary description for Class1.
///
public class MyClassName
{
public MyClassName()
{
//
// TODO: Add constructor logic here
//
}
public Hi()
{
szPassed = "Hi.";
}
}
}
MyClassName works as far as debugging, but Hi doesn't it says:
Class, struc, or interface must have a return type
What does that mean?
-- modified at 20:06 Friday 10th February, 2006
|
|
|
|
|
Your public Hi() is what it's complaining about. You haven't specified what the return type is, even if it's not supposed to have one (void ).
using System;
namespace MyClassNameDLL
{
public class MyClassName
{
public MyClassName()
{
}
public void Hi()
{
string szPassed = "Hi.";
}
}
}
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Ok, so I have a reference to the DLL file. How do I do the using statement?
Right now it is:
using MyClassNameDLL;
What else do I need?
|
|
|
|
|
Add a Reference to the MyClassNameDLL PROJECT, not the .DLL file. Since you're still developing the .DLL, it'll make changes easier when you recompile the app that's using this DLL.
Right-click the References folder, pick Add Reference. Click the Projects tab, then highlight your .DLL project (I'm assuming both projects are in the same solution!), then click OK.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
If your using Visual Studio be sure to add a reference to it
By right clicking the name of your project and selecting add reference in the solution explorer.
Browse to your .dll and select it.
if you have:
using MYClassNameDLL;
at the very top of your code
You are now ready to use your .dll in your code.
Hope this helps
|
|
|
|
|
When I want to use a function within the DLL how do I use it?
Usually I do:
Hi();
|
|
|
|
|
It's looking like you REALLY need to pick up a book on C#. The questions you've asked in this thread are all beginning concepts in programming, let alone C#.
GENERALLY, since you've imported the namespace your class sits in (the using statement at the top of the code), you can just create an instance of your class and call its Hi method:
MyClassName myClass = new MyClassName();
myClass.Hi();
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Two things:
1st:
Although I don't take offense to you saying I don't know how to code, I have to say you are wrong. I do my time in coding with ASP.NET applications in which my employer require the code sit in a single .cs file. They don't want seperate .dlls or any other file except for files such as pictures. I am creating this program on my own to help me with a game I play.
2nd:
I am having no problem getting to the functions on the DLL, I have done what you stated above, but usually when you use a DLL you don't end up having to do things like MyClass.MyFunctions.
Thanks for the help.
|
|
|
|
|
ExpertComing wrote: I am having no problem getting to the functions on the DLL, I have done what you stated above, but usually when you use a DLL you don't end up having to do things like MyClass.MyFunctions.
You're thinking of the time when these were actually called "functions". In an OOP model, they're called "methods".
There are different access levels for methods. The example I showed you is one where an instance of the host class must be created before you can call the method on that instance. Static methods don't require and instace, but you stil have to specify the class that is hosting them. You can either directly specify the host class, like MyClassName.Hi(); , or, if you change the using statement to using MYClassNameDLL.MyClassName; , you can shorten the method call to Hi(); . While it's easier to type, it leaves the source of the method a bit vague and makes your code harder to read.
ExpertComing wrote: Although I don't take offense to you saying I don't know how to code, I have to say you are wrong. I do my time in coding with ASP.NET applications
In what language? ASP.NET is just a web page generation technology. The concepts you're refering to are still very basic, Beginning C# - Week #1, concepts. I don't see how you could possible write an ASP.NET app in C# without knowing the things you're asking about already.
I'm not here to insult you or ridicule your abilities. I'm just give you some advice based on the skill level of your question. If you are just starting out in C#, then you're best, fastest, method of learning this stuff is going to be a book. You'll get these questions answered far faster in those pages that you could in any forum.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well, I would always have all my code in one class, it becomes a slight mess, but it was easy. I have 3 books, I'll read them, thanks for the help, and the advice. I was used to Visual Basic 5, before .NET. You are right about the functions verse methods thing, thanks.
|
|
|
|
|
Hi All.
I'm using visual studio 2005.
1.When i minimize my application i want that the icon will appear like troy icon (near to windows clock ) and not in the main task bar.
How i do it ??
2.I need to create 2 list in my application. In those list i need to add some string`s.
I don't know what control i need to use to do it . I want to do it in some way that in each list i will grid and each string will be write in grid line.
Thanks for help.
|
|
|
|
|
Answer to Question 1:
Search CodeProject for arcticles on tray or taskbar programs
Answer to Question 2:
Depending on what kind of data you are pulling you have two options:
Set amount of date(You know there are only or a max of 100 items):
Use an array
Undefined amount of data(1-Infinite):
Use a list
Hope that helps
|
|
|
|
|
1. Showing an icon in the system tray instead of the taskbar is really quite simple:
To do this, create a new notify icon object.
NotifyIcon icon;<br />
<br />
...<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
icon = new NotifyIcon();<br />
<br />
icon.Icon = this.Icon;<br />
<br />
icon.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);<br />
<br />
icon.Visible = true;<br />
<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{ <br />
this.Hide(); <br />
}<br />
<br />
private void notifyIcon1_DoubleClick(object sender, EventArgs e)<br />
{<br />
this.Show();<br />
}
To not show the form in the taskbar simply set the ShowInTaskbar property of the form to false, and your set!
2. I'm not sure that I fully understand what you mean but based on what you've said a listview control comes to mind.
|
|
|
|
|