|
-
March 13th, 2005, 05:06 PM
#1
Problem with a find button
I'm have a problem with a find button. Here is my code for the button
Code:
private void btnFind_Click(object sender, System.EventArgs e)
{
try
{
this.oleDbDataAdapter1.SelectCommand.CommandText =
"SELECT * FROM Table1 WHERE firstname = "+ this.txtFirstName.Text;
//clear the dataset from the last operation
dataSet11.Clear();
this.oleDbDataAdapter1.Fill(this.dataSet11.Tables["Table1"]);
}
catch(System.Data.OleDb.OleDbException exp)
{
MessageBox.Show(exp.ToString());
}
//copy the dataset in datatable object
DataTable dataTable = dataSet11.Tables[ 0 ];
//if the row count = 0 then the qurey return nothing
if ( dataTable.Rows.Count == 0 )
MessageBox.Show("Record not founded");
}
The error im getting is
System.Data.OleDb.OleDbExepetion: No value given one or more required parameters.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(int32hr)
at Sytem.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResults)
***bunch more things like this***
and the last line says this
at windowsApplication4.Form1.btnFind_Click(Object sender, EventArgs e) in C:\documents and settings\owner\my documents\visual studio projects\windowsapplication4\windowsaplication4\form1.cs : line 294
Ok the line 294 is:
this.oleDbDataAdapter1.Fill(this.dataSet11.Tables["Table1"]);
If any one can help thanks
-
March 13th, 2005, 05:55 PM
#2
Re: Problem with a find button
Should be
Code:
"SELECT * FROM Table1 WHERE firstname = '"+ this.txtFirstName.Text + "'";
Your missing your ' '
Because if first name was Joe Shmoe, then your entering in more than 1 value hence the exception. Encase it in ' ' and your fine.
Hope this helped.
Will Rate Posts for help!
-
March 13th, 2005, 06:12 PM
#3
Re: Problem with a find button
Ok i put in the ' ' and now if i type a name that is in my database it does not fill my other fill. If i put some name that is not in the database i get my messagebox saying Record dont found. I think the problem now it the Fill command:
this.oleDbDataAdapter1.Fill(this.dataSet11.Tables["Table1"]);
Last edited by cmore; March 13th, 2005 at 06:26 PM.
-
March 13th, 2005, 06:26 PM
#4
Re: Problem with a find button
Thats because you only have and if not found, no else MessageBox.Show("Record Found"); blah blah
Will Rate Posts for help!
-
March 13th, 2005, 06:44 PM
#5
Re: Problem with a find button
As you can tell im a newbie to this programming so could you tell my how to write a if else statement. I've tried this:
if (dataTable.Rows.Count == 1)
MesssageBox.Show ("Record Found")
else (dataTable.Rows.Count == 0)
MessageBox.Show ("Record Not Found");
but this does not work.
-
March 13th, 2005, 06:50 PM
#6
Re: Problem with a find button
Ok I fix the problem with the message box thing here it the code.
Code:
if (dataTable.Rows.Count == 0)
{
MessageBox.Show("Record not founded");
}
else
{
MessageBox.Show("Record Found");
}
But it does not fill in the fill with the info that is found.
-
March 13th, 2005, 07:05 PM
#7
Re: Problem with a find button
this.oleDbDataAdapter1.Fill(this.dataSet11.Tables["Table1"]), "Tablename";
Your missing your table name?
Will Rate Posts for help!
-
March 13th, 2005, 07:14 PM
#8
Re: Problem with a find button
this.oleDbDataAdapter1.Fill(this.dataSet11.Tables["Table1"]),
My table name is Table1 so should the code look like this
this.oleDbDataAdapter1.Fill(this.dataSet11.Tables["Table1"]), "Table1";
Look at the code above this i dont think it is work either.
Code:
//clear the dataset from the last operation
dataSet11.Clear();
this.oleDbDataAdapter1.Fill(this.dataSet11.Tables["Table1"]);
should the first line of code be some thing like this
this.dataSet11.Clear();
Last edited by cmore; March 13th, 2005 at 07:23 PM.
-
March 13th, 2005, 07:36 PM
#9
Re: Problem with a find button
this.oleDbDataAdapter1.Fill(this.dataSet11, "Table1");
This will fill in your query into the dataset into Table1
check the name of the DataAdapter something is telling me it should be
OleDbDataAdapter1 assuming you used the toolbox.
The clear line is fine.
Will Rate Posts for help!
-
March 13th, 2005, 07:47 PM
#10
Re: Problem with a find button
Ok i checked
this.oleDbDataAdapter1.Fill(this.dataSet11.Tables["Table1"];
is it oleDb not OleDb
-
March 13th, 2005, 07:57 PM
#11
Re: Problem with a find button
Ok i fixed the problem i forgot to go in the property in the form to bind the txtFirstName to my firstname in my database. It work great thanks for all the help.
-
March 13th, 2005, 08:22 PM
#12
Re: Problem with a find button
Ok good
Will Rate Posts for help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|