Monday, March 26, 2012

Validating Field in code behing page Using Gridviews and sql 200 table

Hello,

I have a detialview which is set for inserting new records into a table (table1) using adapter.

I have 2 fields , field1, field2 that determines its uniqueness.

When inserting a new row, how do i check that this uniqueness exists, and if does not, then a pop up screen should appear stating so.

Your help will be appreciated

Minaz

I think you need to use IF NOT EXISTS in your SQL statement. Its prob most efficient to create it as a SQL stored procedure and call that.

My aplogies - did not clarrify what language I am using.

I do all the codeing behing page with c #. My idea was to retrieve data from database to match the id i enter in my new record and if it exists then I display a message.


My aplogies - did not clarrify what language I am using.

I do all the coding behing page with c #. My idea was to retrieve data from database to match the id i enter in my new record and if it exists then I display a message.


Hi mkh786,

IF NOT EXISTS is a good way in your case.

In c# code you can check the return value of ExecuteNonQuery:

int i = cmd.ExecuteNonQuery();
Response.Write(i.ToString() + " row(s) has been written to test");

If i=0 you can display a message to indicate duplicate insert.

No comments:

Post a Comment