|
I had actually tried that before based on Colin's comments...
private void btnSearchPartNumber_Click(object sender, System.EventArgs e)<br />
{<br />
strPartNumberInput = txtPartNumber.Text;<br />
int partNumber = Convert.ToInt32(strPartNumberInput);<br />
string SQLString = "Select * FROM Costs c INNER JOIN Parts p ON c.PartID = p.Id where p.PartNumber = @PartID"; <br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = new SqlConnection(strConnectSQL);<br />
cmd.CommandText = SQLString;<br />
cmd.Parameters.Add ("@PartID", partNumber);<br />
BindGrid (strConnectSQL, cmd, DataGrid1);<br />
}
When I compile I get these errors:
The best overloaded method match for 'WebBasedPartsDB.WebForm1.BindGrid(string, string, System.Web.UI.WebControls.DataGrid)' has some invalid arguments
Argument '2': cannot convert from 'System.Data.SqlClient.SqlCommand' to 'string'
I don't understand how 'cmd' is invalid? Does the second error have something to do with the convert to int32?
|
|
|
|
|
cmd is not a string, which is why the compiler won't let you treat it as one. Change the signature of the BindGrid method so that it accepts a SqlCommand.
This will be my last reply on this thread.
Good luck,
Josh
|
|
|
|
|
Continuing from Josh's last comment:
Call BindGrid like this:
BindGrid(cmd, DataGrid1);
private void BindGrid (SqlCommand cmd, System.Web.UI.WebControls.DataGrid DGrid)
{
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds);
DGrid.DataSource = ds;
DGrid.DataBind();
conn.Close();
}
All that was done here was the the first two parameters, the connection string and the command string , were replaced with one SqlCommand object.
The call to BindGrid similarly replaces the strings with a SqlCommand object.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Since 'conn' is not in BindGrid, I'm not sure what to close. I played around with the code, but it's not compiling.
|
|
|
|
|
leckey wrote: Since 'conn' is not in BindGrid, I'm not sure what to close
But it is in cmd - see SqlCommand.Connection[^]
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
RadioButtonList and CheckBoxList both share certain common properties
(e.g.
RepeatColumns
RepeatDirection
RepeatLayout )
However these properties are not inherited from a common ancestor.
Is there any neat way I can have 1 common function accepting either a RadioButtonList or CheckBoxList and use these properties within the function method without having to check the type and then casting to 1 or the other?
|
|
|
|
|
You could do it with reflection. But that's about it.
|
|
|
|
|
You could create your own class which wraps either a RadioButtonList or a CheckBoxList and exposes those common properties. It still wouldn't be an entirely statisfactory solution, but at least it would hide all the messy type checking and casting.
|
|
|
|
|
Thanks for the responses.
I was just checking that I wasn't missing something obvious.
Cheers.
Martin
|
|
|
|
|
Hi All,
Can custom http handler be designed such a way that it acts as a http server. Is it possible for custom HTTP handler to generate HTTPRequest and receive response for that request.
Thanks
|
|
|
|
|
Hi All,
Wanted to know how to add and remove HTTP header information to HTTPWebRequest and HTTPWebResponse objects. The IIS will add automatically some headers which is unwanted for processing. e.g Server Info, Charset info.
While sending HTTP request to HTTP server only few headers needs to be sent and while responding to a request need to send few headers.
Thanks
|
|
|
|
|
Hai all,
My developement area is ASP.net & c#.
I have one lake records to update to database in my module
i can't identify which way is best way.
i am try to open XML.please give any other suggestion
regards
Munusamy
-- modified at 0:26 Friday 9th June, 2006
|
|
|
|
|
Hi Im a beginner
and need some help.
I am having a problem with passing an object through to another object.
To clarify, I have created an instance of an object and now want to pass that instance with all its properties through to a CustomTabPage object.
Customer acustomer = new Customer(CustName, CustPhone);
CustomerTabPage customerTab = new CustomerTabPage(acustomer);
In my CustomerTabPage class, acustomer.Name brings back a null value. when it should bring the name that was passed through CustName.
Hope what im asking makes sense.
|
|
|
|
|
rcwoods wrote: In my CustomerTabPage class, acustomer.Name brings back a null value.
Then either
- your Name property is really null
or
- your acustomer is null
Add checks like if(acustomer == null || acustomer.Name == null || ...) to verify your Customer object is valid.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hello,
In my form application, i am having controls like ListBox, ComboBox and OK - Cancel buttons.
I want to get the proper combition of inserted item in ListBox and comboBox.
So when user press OK, if the combination is not proper the control should return to form to select the another combination.
To achieve this i handled the validating event of comboBox but now this does not give me chance to change the selection from ListBox unless and untill i change the selection from ComboBox.
How should i handle it.
Also if i am calling a method from OK button and if the method returns false the form should not be disposed.
Thanks.
gajesh
Pune(India)
|
|
|
|
|
Handle the Closing event of the Form. If the data in the controls is invalid, set e.Cancel to true. You can check the Form's DialogResult property to see which button was clicked (OK or Cancel).
Josh
|
|
|
|
|
I have a datagridview created. Is it possible to allow user to do a search on the data?
|
|
|
|
|
I know there is an article here on Code Project that lets the user basically create SQL statements to return records. I've been researching datagrids myself; if you search on it you will get lots of articles. It may take a little time to search through them, but chances are you will find what you need.
Also from what I understand, VS2005 will let you treat cells individually more easily rather than as an entire row like VS2003. So that may make a difference on how you decide to program.
Hope your search turns out well!
|
|
|
|
|
I've got an app that does heavy background processing off a user adjustable timer. If the tick rate is pushed too fast and all the CPU capacity is hogged by the background activity, or the app's running near the limit and annother process starts eating heavy cycles my app stops behaving well. The most prominant issue is that the form doesn't handle the OnPaint event. Is there an easy way to test that the event is being handled so that I can throttle the timer.
|
|
|
|
|
In source code, you can check by comparing that event against null. If the event is equal to null, it means corresponding event is not being handled. Otherwise, it is being handled.
|
|
|
|
|
You misunderstand what I need. The default event handler for OnPaint is installed, but if the other stuff my app does in the background is being called to rapidly the event handler never actually gets called. I'm using a high precision win32 timer that IIUC uses a high priority kernal thread to repeatedly check a high precision clock and fire events to my app. If it's set too rapidly (and too rapid depends on the cpu speed and it's background process load), the timer itself can consume 100% of my app's cpu time, and my apps OnPaint event handler stops being executed.
|
|
|
|
|
I might get you wrong, too, but why don't you just add your own method to the event handler, which for example saves the time when it was executed in a variable, that you can check in your code. You might also override the OnPaint method of your form to do the above procedure:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)<br />
{<br />
lasttimeexecuted = DateTime.Now;<br />
base.OnPaint(e);<br />
}
-- modified at 12:21 Wednesday 7th June, 2006
|
|
|
|
|
3Dizard wrote: I might get you wrong, too, but why don't you just add your own method to the event handler, which for example saves the time when it was executed in a variable, that you can check in your code.
That sounds like it should work. Apparently my brain's been thinking it's friday 4:30pm all day.
|
|
|
|
|
Hi Guys,
I need to read and write records in my C# app to a binary file like these
class myRecord
{
string filed1;
Int32 field2;
Int32 sizeOfData;
byte[] data;
}
or
[StructLayout(LayoutKind.Sequntial)]
struct myRecord
{
//Same thing
}
Actually I read sequentially record's fileds so I do sequentially calls to read string, Int32...with methods of BinaryReader, BymaryWriter classes.
What is the method/best way to read/write this type of data?There are tuts or examples on codeproject?
Thankyou a lot in advance.
Mirko
|
|
|
|
|
I'm trying to get my deployment project to automatically associate a certain file extension with my .exe.
When I run my installer, the program installs normally, and all files with my desired extension change to an icon representing my applcation. When I double click these files, my application loads as expected.
The problem is when I right click one of these files, and select open with. The icon is blank, and the description of the application used to open it is empty.
My question is, in the setup and deployment project, where is the area where I place a target icon and a description, so that it will show up on the "Open With" list of file associations?
Also does anyone know how to clean the "Recommended Programs" list in this menu?
Thanks,
-Chris
|
|
|
|