|
Okay, so the part number the user enters is an alpha-numeric id that never really gets used again. The SQL table Parts has two fields: Parts.PartNumber (which is what the user enters) and Parts.Id (which is the actual field that I have to match up with in Costs.PartID). Do I basically have to repeat everything to get that field before joining with costs? What I mean is, if I do Colin's reference:
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = new SqlConnection(strConnectSQL);<br />
cmd.CommandText = SQLString;<br />
cmd.Parameters.Add ("@PartID", partNumber);
And I want to do another @TruePartId (or something like that) do I have to go through the SqlCommand cmd = new SqlCommand again?
I'm so sorry...my head is swimming...thank you guys so much for explaining this.
|
|
|
|
|
Maybe it's me, but I'm not clear on what you're asking. You might want to elaborate a little bit on the situation.
leckey wrote: do I have to go through the SqlCommand cmd = new SqlCommand again?
Copy-and-paste helps alleviate the pain.
Josh
|
|
|
|
|
Basically my code is missing a step. Right now the user enters the Part Number (Parts.PartNumber which is a varchar). Right now the code says, okay give me info from costs where Costs.PartID matches Parts.PartNumber. But it's never going to match up because I missed a step.
For example, product C15690 has an ID of 5499. This is what I need to match.
Right now the code goes like this....
Costs.PartID = Parts.PartNumber
Should be...
First get Parts.ID based on Parts.PartNumber (missing step)
Costs.PartID = Parts.ID
private void btnSearchPartNumber_Click(object sender, System.EventArgs e)<br />
{<br />
strPartNumberInput = txtPartNumber.Text;<br />
int partNumber = Convert.ToInt32(strPartNumberInput);
string SQLString = "Select * FROM Costs where Costs.PartID = @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, SQLString, DataGrid1 );<br />
}
Oh, I hope this explains it!
|
|
|
|
|
Your SQL query needs to join the Costs and Parts table on the part ID. You will only need one call to the database. Something like:
SELECT *
FROM Costs c INNER JOIN Parts p On c.PartID = p.ID
WHERE p.PartNumber = @PartNumber
Josh
|
|
|
|
|
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, SQLString, DataGrid1 );<br />
}
Okay, when I try to load in the brower I get the error that I need to declare the variable '@PartID.'Since this is a reference with the @ sysmbol do I declare it differently or just declare it like a normal variable?
...thanks again for your help. I really appreciate you taking your own time to help me.
|
|
|
|
|
It looks like you need to pass cmd into the BindGrid method. As of now, the parameter you added to cmd is not being used because cmd is not being used.
josh
|
|
|
|
|
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.
|
|
|
|