|
I'm writing a small app, and I have to prepare a form which will authenticate users. This is the code I wrote. The problem is I get exception in the marked line : "no value given for for on or more required parameters"
What is wrong with it?
Table name is users.
Column name is UserName
<br />
public void userExists(string username)<br />
{<br />
try<br />
{
string sqlFinduser = "SELECT COUNT(UserName) AS UserNameExists " +<br />
"FROM users " +<br />
"WHERE (UserName=" + username + ")";<br />
<br />
OleDbCommand cmdFindsqlFinduser = new OleDbCommand();<br />
<br />
cmdFindsqlFinduser.Connection = cnSurvey;<br />
cmdFindsqlFinduser.CommandType = CommandType.Text;<br />
cmdFindsqlFinduser.CommandText = sqlFinduser;<br />
<br />
cnSurvey.Open();<br />
<br />
int count = int.Parse(cmdFindsqlFinduser.ExecuteScalar().ToString()); <br />
<br />
bool exists = count != 0 ? true : false;<br />
<br />
cnSurvey.Close();<br />
<br />
}<br />
catch(Exception ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
<br />
}<br />
<br />
TIA,
Ronen
|
|
|
|
|
That means that you have one or more names in your query that the database does not regognise.
You have forgotten the apostrophes around the value for username. The database will try to interpret the username as being an identifier, not a string.
---
b { font-weight: normal; }
|
|
|
|
|
How about changing
(UserName=" + username + ")"
to
(UserName='" + username + "')"
assume: username = "abc"
Current code: (UserName = abc)
Fixed code: (UserName = 'abc')
|
|
|
|
|
|
Hey everyone, a quick thanks for taking a look at this...
Basically, my problem is this... I have a "Core" library which contains a "Manager" component, and I want to use this component in C#. This component is written in C++, and here is the IDL file defining its type library.
<br />
import "unknwn.idl";<br />
<br />
[<br />
object,<br />
uuid(822A2EDE-09F1-45b8-B80E-A32F21415677),<br />
helpstring("Interface used by the Manager")<br />
]<br />
<br />
interface IManager : IUnknown<br />
{<br />
HRESULT GetAppName([out, size_is(, *pcMax)] char **ppAppName,<br />
[out] long *pcMax);<br />
<br />
HRESULT SetStatus([in] long cLength,<br />
[in, size_is(cLength)] char* id,<br />
[in] int s);<br />
};<br />
<br />
[<br />
uuid(AE068C74-0B8B-4041-8CA9-4A590DDDC382),<br />
helpstring("Core Component Library")<br />
]<br />
library Core<br />
{<br />
importlib("stdole32.tlb");<br />
importlib("stdole2.tlb");<br />
<br />
interface IManager;<br />
}<br />
Now, if I write a C++ app to use this component, doing this, it works great...
(Keep in mind, the component is registered in the registry and the DLL creates an instance of the component by using IClassFactory)
<br />
#include "stdafx.h"<br />
#include <objbase.h><br />
#import "Core.tlb"<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
HRESULT hr = NULL;<br />
CLSID clsid;<br />
<br />
::CoInitialize(NULL);<br />
<br />
Core::IManager* pManager;<br />
hr = CLSIDFromProgID(OLESTR("Core.1"), &clsid);<br />
<br />
if(FAILED(hr))<br />
{<br />
cout << "DLL not installed correctly" << endl;<br />
}<br />
<br />
hr = ::CoCreateInstance(clsid, NULL, <br />
CLSCTX_ALL, __uuidof(Core::IManager), (void** )&pManager);<br />
<br />
<br />
if(SUCCEEDED(hr))<br />
{<br />
cout << "Found component!" << endl;<br />
<br />
}<br />
}<br />
No problem, it executes just fine, my C++ app easily uses the component.
Now, I try importing "Core.tlb" into .NET, by using tlbimp.exe, I get a useless managed assembly... After pouring through MSDN article after MSDN article, I've come to the conclusion that its possible to create a COM class wrapper? However, I've had no luck with that as well... This is all I've been able to come up with, but I know it doesn't work...
<br />
namespace Core<br />
{<br />
[Guid("822A2EDE-09F1-45b8-B80E-A32F21415677"),<br />
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]<br />
interface IManager<br />
{<br />
void GetAppName(<br />
[Out, MarshalAs(UnmanagedType.BStr)] string strAppname,<br />
[Out] int maxSize);<br />
<br />
void SetTestPointStatus(<br />
[In] int MaxLength,<br />
[In, MarshalAs(UnmanagedType.BStr)] string id,<br />
[In] int status);<br />
}<br />
<br />
[ComImport, Guid("AE068C74-0B8B-4041-8CA9-4A590DDDC382")]<br />
class CManager<br />
{<br />
}<br />
}<br />
Anyone have any suggestions? I've come to the conclusion that I really have no idea what I'm doing in C# as far as interop goes, I'm not a bad C# coder, but this just escapes me at the moment...
Anyway, thanks again for reading this
|
|
|
|
|
Hi!
In your C# project, just add a reference to your COM object (in project explorer, select "Add reference..." and find your COM class on the COM tab).
VS.NET will create the interop assembly and you can immediately use your COM class.
Typing "Core." should already give you intellisense for IManager, CManager and so on.
Regards,
mav
|
|
|
|
|
First, thank you very much for your advice...
Hmmm, I've tried that, but like I said, I don't really have that usable of an interop assembly... It only gives me Core::IManager, just the interface... Do I have to implement that interface, or write a wrapper for that? There are no class objects for me to instantiate... Some sites talk about coclasses, but I have none defined in my IDL file, and I'm not really sure what I'm doing as far as that... haha, am I just doing this wrong?
Thanks again
|
|
|
|
|
Ok, now that I've taken a second look at the IDL, there in fact isn't a CoClass defined, so all you'll get will be IManager. This is correct so far.
What puzzles me is that you claim that it does work with C++/CoCreateInstance...
I didn't find any class actually implementing IManager, so which class is created by the class factory?
mav
|
|
|
|
|
I have a program, it's a form, a GUI. I need it to close when I hit the x-button in the corner. It is still running in the processes after I close it. How do I permenantly kill the program?
I tried this:
private void ExitButton_Click(object sender, System.EventArgs e)
{
this.Close();
}
thanks very much!
|
|
|
|
|
You want to register on the Form_Closing event.
private void Form1_Closing(object sender, CancelEventArgs e)<br />
{<br />
if (should Not Close)<br />
e.Cancel = true;<br />
}
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
I'm writing an app that needs to write to a database (database file...like mdf) with out having to install one (like SQL server or Access). Are there any examples on how to do this in C#?
What is the best practice for writing an app that needs database support but is not network aware?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
take a look at Firebird
www.firebirdsql.com
it kan be used in embedded mode
so u only need a dll (1,5MB) in the app folder and you have a full RDBMS
|
|
|
|
|
So do I need to download the .net data provider for framework 1.1? Or is there more to it?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
I've used VistaDB in the past. It has only a 500KB footprint, and a fully featured .NET data provider for use with ADO.NET.
Check http://www.vistadb.com[^].
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
You don't have to install Microsoft Access to use an Access database. The drivers come with windows.
---
b { font-weight: normal; }
|
|
|
|
|
So I can use access and just make my connection string point to a specific file?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Yes.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
How can I add a Delete button to a datagrid, to delete a row?
I added an Edit Command by , its working fine, but how to add a delete command?
Thanks
|
|
|
|
|
hi can someone pls help urgent getting this error, earlier was working fine and had no problems suddenly this error arises.
Server Error in '/DulcineaSalesLedgerSolution' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 2393: }
Line 2394:
Line 2395: dgInv1.DataSource = objRightDataSet.Tables["GetInvGrid"].DefaultView;
Line 2396: DataTable objInvTable = new DataTable("GetInvGrid");
Line 2397: objInvTable = objRightDataSet.Tables["GetInvGrid"];
Source File: c:\inetpub\wwwroot\dulcineasalesledgersolution\inventory.aspx.cs Line: 2395
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\dulcineasalesledgersolution\inventory.aspx.cs:2395
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
Zindagi
|
|
|
|
|
You are trying to use a reference that is null.
The most probable reason for this is that there is no table by that name in the data set.
---
b { font-weight: normal; }
|
|
|
|
|
but it was working earlier and had no problems with it, suddenly this thig pops up, please help.
Thanks,
|
|
|
|
|
That it was working before is not a guarantee that it is correct...
You have to examine how you populate the data set to find the reason why the table is missing or has a different name.
If the data set is supposed to contain a single table, you can access it using it's index (0) instead. Then the name does not matter.
---
b { font-weight: normal; }
|
|
|
|
|
dgInv1.DataSource = objRightDataSet.Tables["GetInvGrid"].DefaultView;
it gives me error on the above line, and the ["GetInvGrid"] is not a table but a stored procedure.
I really appreciate your help thanks once again, I have a demo to show and I am stuck
Thanks,
|
|
|
|
|
|
Zindagi11@rediffmail.com wrote:
["GetInvGrid"] is not a table but a stored procedure.
This is your problem then. Did you actually execute that stored procedure? Did it return a table called "GetInvGrid"? If not, this is where your problem is! How do you fix it? Well, that's up to how you wrote your code that fills this table.
The reason you're getting this NullReference error is because you don't have a table in your dataset object that's called "GetInvGrid". Since you don't have that table, you can't get its .DefaultView property!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|