Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a problem

I'm busy writing a C#.NET project but walked into a problem.

 

I've got a Form With 3 Textboxes a Button and a DataGrid.

 

If i typ a value into the textboxes and i press the button. The datagrid Shows me the correct data.

 

 

this.oracleSelectCommand1.CommandText = @"SELECT Collom1, Collom2, Collom3, Collom4, Collom5

FROM Database

WHERE (Collom1 = :PARAM2)

AND (Collom2 = :PARAM3)

AND (Collom3 = :PARAM4)";

 

 

But now i want it like This:

If i Typ a value for the first and last colom and not the second one.

I still want him te show me the data he found and ignore the Where at "PARAM3".

If i do this now he says that he haven't got enough info to fill op my dataAdaptor.

Wich is logic.

But i realy don't have a clue how to do this.. can you help me?

Posted

Hey,

 

Can't you just do this.

If the textbox is empty than the value to search is by default % (wildcard).

 

Regards.

 

I have a problem

I'm busy writing a C#.NET project but walked into a problem.

 

I've got a Form With 3 Textboxes a Button and a DataGrid.

 

If i typ a value into the textboxes and i press the button. The datagrid Shows me the correct data.

 

 

this.oracleSelectCommand1.CommandText = @"SELECT Collom1, Collom2, Collom3, Collom4, Collom5

FROM Database

WHERE (Collom1 = :PARAM2)

AND (Collom2 = :PARAM3)

AND (Collom3 = :PARAM4)";

 

 

But now i want it like This:

If i Typ a value for the first and last colom and not the second one.

I still want him te show me the data he found and ignore the Where at "PARAM3".

If i do this now he says that he haven't got enough info to fill op my dataAdaptor.

Wich is logic.

But i realy don't have a clue how to do this.. can you help me?

Posted (edited)
Hey,

 

Can't you just do this.

If the textbox is empty than the value to search is by default % (wildcard).

 

Regards.

 

 

If I type a % into my textboxes as Values in the running program. he give's a error that he also gives when i leave a textfield blank.

 

suppose the code would look like this:

 

if (txtBorgtochtNummer.Text == string.Empty)

{

oracleDataAdapter1.SelectCommand.Parameters[":PARAM2"].Value = "%";

}

else

{

oracleDataAdapter1.SelectCommand.Parameters[":PARAM2"].Value = txtBorgtochtNummer.Text;

}

Or am I wrong..

Edited by rmokkenstorm
Posted

What is the error that you get?

Maybe try to step trough the code to see if he does the check correctly

 

realized something, if you use wildcards that you have to you LIKE and not = in your SQL statement ... if I am not mistaking.

 

Greetz,

 

If I type a % into my textboxes as Values in the running program. he give's a error that he also gives when i leave a textfield blank.

 

suppose the code would look like this:

 

if (txtBorgtochtNummer.Text == string.Empty)

{

oracleDataAdapter1.SelectCommand.Parameters[":PARAM2"].Value = "%";

}

else

{

oracleDataAdapter1.SelectCommand.Parameters[":PARAM2"].Value = txtBorgtochtNummer.Text;

}

Or am I wrong..

Posted
What is the error that you get?

Maybe try to step trough the code to see if he does the check correctly

 

realized something, if you use wildcards that you have to you LIKE and not = in your SQL statement ... if I am not mistaking.

 

Greetz,

 

yes that's true .. it's prety strange cause if i only execute the query in SQL plus. There's no problem.. i quote them between ' ' and it works...

now my script. including the IF, ELSE.. works.. but I have Still have to Fill up all the fields.

If I don't he notice me that my OracleDataAdaptor1.Fill is not correct.. witch is pretty logic. cause he misses one parameter..

 

Conculusion: My If, Else is not correct or I do not place my Quotes Correct.

Posted

God i'm supid...

Left the fields on number..

No wonder it didn't work..

But... now they are on varchar it works almost like I want it.

 

if (":PARAM2" != string.Empty)

{

oracleDataAdapter1.SelectCommand.Parameters[":PARAM2"].Value = txtBorgtochtNummer.Text;

}

else

{

oracleDataAdapter1.SelectCommand.Parameters[":PARAM2"].Value = "%";

}

 

Why doesn't he put the "%" into his param.

I don't want to let the user fill in a %.. or set the textbox at "%" ..

why does the system not fill this in itself?

Posted (edited)

private void btnbutton1_Click(object sender, System.EventArgs e)
{
		
if ((string)oracleDataAdapter1.SelectCommand.Parameters[":PARAM2"].Value == string.Empty)
{
oracleDataAdapter1.SelectCommand.Parameters[":PARAM2"].Value = "%";
}		
else
{				
oracleDataAdapter1.SelectCommand.Parameters[":PARAM2"].Value = txtBorgtochtNummer.Text;
}

if ((string)oracleDataAdapter1.SelectCommand.Parameters[":PARAM3"].Value == string.Empty)
{
oracleDataAdapter1.SelectCommand.Parameters[":PARAM3"].Value = "%";
}		
else
{
oracleDataAdapter1.SelectCommand.Parameters[":PARAM3"].Value = txtBorgtocht2.Text;				
}

if ((string)oracleDataAdapter1.SelectCommand.Parameters[":PARAM4"].Value == string.Empty)
{
oracleDataAdapter1.SelectCommand.Parameters[":PARAM4"].Value = "%";
}		
else
{				
oracleDataAdapter1.SelectCommand.Parameters[":PARAM4"].Value = txtBorgtocht3.Text;
}

dataSet11.Clear();
oracleDataAdapter1.Fill(dataSet11);
		
}

 

Seems good doesn't it?

But ...

If I do not type any values into the textboxes I have to click twice at the submit button.

If I type al of the values into the textboxes I only have to click once.

 

If Fill in a single value in one textbox and press the button he doesn't show data. Then I type the second value in another textbox and pres the button.

He show's me the data from the previos value. The single value that is.

After that the program is some kind of bugged cause no matter what I type.

No data will be shown annylonger.

Edited by PlausiblyDamp
  • Administrators
Posted

Where are you actually binding the controls to the dataset? Where is the dataset declared? If you could post more of the relevant code it might help...

 

It looks as though you are doing the binding in the Page_Load event but binding against the dataset loaded on the previous button click.

Also are you sure you mean to check the parameters' current value agains string.empty rather than the textbox content's agains string.empty.

In your code the first time it is executed each parameter is probably empty so you set it to '%', on subsequent executions they will not be empty and so you then assign the textbox contents to the control regardless of the textbox's value.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
Where are you actually binding the controls to the dataset? Where is the dataset declared? If you could post more of the relevant code it might help...

 

It looks as though you are doing the binding in the Page_Load event but binding against the dataset loaded on the previous button click.

Also are you sure you mean to check the parameters' current value agains string.empty rather than the textbox content's agains string.empty.

In your code the first time it is executed each parameter is probably empty so you set it to '%', on subsequent executions they will not be empty and so you then assign the textbox contents to the control regardless of the textbox's value.

 

 

private void InitializeComponent()

{

System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();

this.oracleDataAdapter1 = new System.Data.OracleClient.OracleDataAdapter();

this.oracleDeleteCommand1 = new System.Data.OracleClient.OracleCommand();

this.oracleConnection1 = new System.Data.OracleClient.OracleConnection();

this.oracleInsertCommand1 = new System.Data.OracleClient.OracleCommand();

this.oracleSelectCommand1 = new System.Data.OracleClient.OracleCommand();

this.oracleUpdateCommand1 = new System.Data.OracleClient.OracleCommand();

this.txtBorgtochtNummer = new System.Windows.Forms.TextBox();

this.txtBorgtocht2 = new System.Windows.Forms.TextBox();

this.txtBorgtocht3 = new System.Windows.Forms.TextBox();

this.btnbutton1 = new System.Windows.Forms.Button();

this.dgrdataGrid = new System.Windows.Forms.DataGrid();

this.dataSet11 = new HELLYEAH.DataSet1();

this.cmbcomboBox1 = new System.Windows.Forms.ComboBox();

((System.ComponentModel.ISupportInitialize)(this.dgrdataGrid)).BeginInit();

((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();

this.SuspendLayout();

//

// oracleDataAdapter1

//

this.oracleDataAdapter1.DeleteCommand = this.oracleDeleteCommand1;

this.oracleDataAdapter1.InsertCommand = this.oracleInsertCommand1;

this.oracleDataAdapter1.SelectCommand = this.oracleSelectCommand1;

this.oracleDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[]

 

 

The datasets are automaticly genererated by microsoft visual studio.net 2003

I did not do this on my onw.

 

After I click on the search button he puts the stuff in the dataset. nowhere else.

 

the datagrid src = set on the dataset

 

If i explaind well.

But...

I set the string.empty to the textboxes like you advised en now it works.

stupid thing in the past It was focused on the textbox don't know why I used the param.

 

Short theori (please rely if I'm wrong):

Why the param's didn't work:

If i Do not fill in a value in the textbox and i press on the button.

this is when he's gonna check the param's. now he notice that the are empty and Fill's them up whit the %.

But he already has filled the dataset with empty values not the "%".

 

Is this correct.

It think not cause if I do fill in all fields. he works right away.

 

someknow why it didn't work with param as empty.sting command and as textfield.text it does work?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...