Showing posts with label textbox. Show all posts
Showing posts with label textbox. Show all posts

Wednesday, March 21, 2012

Name Count

I have an sql command for when you add a new name to the database it counts to see how many of the name entered to the textbox exist in the database. If the count is 0 then it will add the name to the table. Else it displays an error message.

This works fine for inserting a new name but on my update page where you may update the name I have the same code which on button click counts to see how many exist. But if you leave the textbox the same value and click the button the count obviously results in 1 and brings up an error message.

Is there a way I can do a count but not including the name that is currently the value of the textbox?

protected void UpdateSharedArea(object sender, EventArgs e) { SqlConnection connection =new SqlConnection(docShare_ConString);//Count the amount of area names that are the same as typed by user SqlCommand existCheck =new SqlCommand("SELECT COUNT(doc_area_name) FROM document_area WHERE doc_area_name = @.doc_area_name", connection); SqlParameter areaname =new SqlParameter("@.doc_area_name", SqlDbType.VarChar); areaname.Value = AreaText.Text; existCheck.Parameters.Add(areaname); connection.Open();int count = (int)existCheck.ExecuteScalar(); connection.Close();//If the area name does not exist within the tableif (count == 0) {//Update name
Cheers, Mark

You will need to to filter your count by the ID of the record you are updating. So when you load the name to display in your textbox, also load the ID of the record and keep it somewhere (Session state or viewstate for example). Then when you do your count, filter on the ID, e.g.

SELECT COUNT(*) FROM NameList WHERE Name = @.Name AND ID != @.Id

|||

Brilliant, thanks very much for the reply.

Mark

Monday, February 20, 2012

My own report parameters

Hi there,
Can I add my own report parameters on report parameter area of a sql server
report 2005.
I have a label, textbox followed by a button. Open a aspx search page
onclicking the button.
Thanks,
RaviI not sure I really understand your question..
However one of the things you can do , create and upload an aspx page to
Reporting Services, which you have programmed to collect any parameter
information you wish. It could also contain a button, that calls your report
URL, passing in the parameter values you have collected.
--
Wayne Snyder MCDBA, SQL Server MVP
Mariner, Charlotte, NC
I support the Professional Association for SQL Server ( PASS) and it''s
community of SQL Professionals.
"Ravi Manda" wrote:
> Hi there,
> Can I add my own report parameters on report parameter area of a sql server
> report 2005.
> I have a label, textbox followed by a button. Open a aspx search page
> onclicking the button.
> Thanks,
> Ravi|||My requirement is something like this, I want to have a label, textbox and
button, on clicking the button I will open a page and the page returns a some
value which should be populted in the textbox. But we don't have control on
report parameter area of a report.
As per my understadning from your reply is I need to have a aspx page with
my own parameters and a reportviewer control pass these parameters with the
URL to the report. (I'm ok with this answer).
Please confirm me that we cann't add our own controls on the report
parameter area.
(We don't want to have a dropdownlist incase the items cross's more then
100. In this case we add a text box and a button on the report parameter
area. Onclicking the button I will open a search page in a popup window).
Search page contains all search fields and a grid. Selecting on a particular
row on the grid I need to pass the value to the textbox of the report).
Thanks
"Wayne Snyder" wrote:
> I not sure I really understand your question..
> However one of the things you can do , create and upload an aspx page to
> Reporting Services, which you have programmed to collect any parameter
> information you wish. It could also contain a button, that calls your report
> URL, passing in the parameter values you have collected.
> --
> Wayne Snyder MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> I support the Professional Association for SQL Server ( PASS) and it''s
> community of SQL Professionals.
>
> "Ravi Manda" wrote:
> > Hi there,
> >
> > Can I add my own report parameters on report parameter area of a sql server
> > report 2005.
> >
> > I have a label, textbox followed by a button. Open a aspx search page
> > onclicking the button.
> >
> > Thanks,
> > Ravi