Ask a Question related to ASP.NET Building Controls, Design and Development.
-
verci #1
Newbie, how to check if a value in a gridview cell already exist in database
Hi
I've the following dataset bound to my gridview
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NwindConnectionString %>"
SelectCommand="SELECT p.ProductID, p.ProductName, p.CategoryID, c.CategoryName FROM Products p inner join Categories c on p.CategoryID = c.CategoryID"
UpdateCommand="Update Products Set ProductID=@ProductID, ProductName=@ProductName, CategoryID=@CategoryID where ProductID=@ProductID"
deletecommand="delete from products where productid=@productid">
<DeleteParameters>
<asp:Parameter Name="productID" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
How can check if a value in a gridview cell already exist in the database?, I use the following to check if the value entered for "ProductName" is null, but I also want to check if the value entered does in fact already exist in my database.
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
If e.NewValues("ProductName") = "" Then
e.Cancel = True
Return
End If
End Sub
Thanks and best regards.
verci Guest
-
Determine Selected Cell in Gridview
Hi all, I have created a row selectable gridview control, however I am looking to add a little more functionality. Currently, I can select a row... -
Newbie, add a button to gridview footer
Hi Can anyone help me or point me in the right direction, I'm running Win XP Pro SP2, VS2005 Team, .Net Framework 2.0 and SQL Server2005. I... -
Newbie, adding a row to Gridview in VB
Hi Can anyone help me or point me in the right direction, I'm running Win XP Pro SP2, VS2005 Team, .Net Framework 2.0 and SQL Server2005. I... -
Newbie, gridview problem Asp.net 2005
Hi Can anyone help me I'm running Win XP Pro SP2, VS2005 Team, .Net Framework 2.0 and SQL Server2005, I can't delete records using the gridviews... -
Cell handling when databinding in a GridView
I have a table with some url's (e.g. MyLinks.) In the database, the table has a field "AllowDelete". The grid is set up with two columns. One... -
anu #2
Re: Newbie, how to check if a value in a gridview cell already exist in database
To check whether data in a cell already exists or not
we have to check the complete column
for that we have to write select query which checks for data to be entered already
exists or not
if it exists we have to come out of program
else continue coding such as updating.
for checking of existing data we use 'hasrows' fn in vb.net
code:
Dim CMD As New OleDbCommand
CMD.CommandText = "SELECT * FROM tablename WHERE D_NAME='" & txtname.Text & "' AND CPD_PK_CODE <> '" & txtpkcode.Text & "'"
dReader = CMD.ExecuteReader
If dReader.HasRows Then
lblmessage.Text = txtname.Text + "- already exists"
Exit Sub
Else
CMD = New OleDbCommand
CMD.Connection = con
CMD.CommandText = "UPDATE tablename SET values"
CMD.ExecuteNonQuery()
here we are checking data which is entered from textboxes
d_name is the column name which we have to check and pk_code is primary key column nameanu Guest
-
alochana9 #3
Re: Newbie, how to check if a value in a gridview cell already exist in database
To check whether data in a cell already exists or not
we have to check the complete column
for that we have to write select query which checks for data to be entered already
exists or not
if it exists we have to come out of program
else continue coding such as updating.
for checking of existing data we use 'hasrows' fn in vb.net
code:
Dim CMD As New OleDbCommand
CMD.CommandText = "SELECT * FROM tablename WHERE D_NAME='" & txtname.Text & "' AND CPD_PK_CODE <> '" & txtpkcode.Text & "'"
dReader = CMD.ExecuteReader
If dReader.HasRows Then
lblmessage.Text = txtname.Text + "- already exists"
Exit Sub
Else
CMD = New OleDbCommand
CMD.Connection = con
CMD.CommandText = "UPDATE tablename SET values"
CMD.ExecuteNonQuery()
here we are checking data which is entered from textboxes
d_name is the column name which we have to check and pk_code is primary key column name
Junior Member
- Join Date
- May 2011
- Location
- hyderabad
- Posts
- 4



Reply With Quote

