Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 20th, 2005, 03:03 AM
Authorized User
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB.NET ExecuteNonQuery() command

When I'm using this code to insert data into databse, when server tries to insert it will complain me about FK in the table. One of the tables columns are a FK to a table. What should I do. When I take the relation away from server it works perfect.
<script runat="server">
protected sub Page_Load(Src as Object ,E as EventArgs)

  if (IsPostBack)
If Page.IsValid then
Dim loConn as New SqlConnection(ConfigurationSettings.AppSettings("M M_CONNECTION_STRING_HWB"))
Dim UDIDS As Integer
Dim cmdInsert as New SQLCommand("reg_userdetails",loConn)
cmdInsert.CommandType = CommandType.StoredProcedure
cmdInsert.Parameters.Add(New SqlParameter("@UDID",SqlDbType.int))
cmdInsert.Parameters("@UDID").Direction = ParameterDirection.Output
cmdInsert.Parameters.Add(New SqlParameter("@UID", SqlDbType.int, 4, "UID"))
cmdInsert.Parameters("@UID").Value = Request("UID")
cmdInsert.Parameters.Add(New SqlParameter("@Fornamn", SqlDbType.nvarchar, 50, "Fornamn"))
cmdInsert.Parameters("@Fornamn").Value = Request("Fornamn")
cmdInsert.Parameters.Add(New SqlParameter("@Efternamn", SqlDbType.varchar, 50, "Efternamn"))
cmdInsert.Parameters("@Efternamn").Value = Request("Efternamn")
cmdInsert.Parameters.Add(New SqlParameter("@Gatuandress", SqlDbType.nvarchar, 50, "Gatuandress"))
cmdInsert.Parameters("@Gatuandress").Value = Request("Gatuandress")
cmdInsert.Parameters.Add(New SqlParameter("@Postnummer", SqlDbType.nvarchar, 5, "Postnummer"))
cmdInsert.Parameters("@Postnummer").Value = Request("Postnummer")
UDIDS = cmdInsert.Parameters("@UDID").Value
end if
    end if
end sub


Old September 20th, 2005, 10:03 AM
Friend of Wrox
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts

The short answer: Fix the data you are inserting. There is a FK relationship on the other table for a reason, data integrity.

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call QBasic command in VB.Net kiwibey Visual Studio 2005 1 January 10th, 2007 11:37 AM
How to use create table command in VB.net ahali ADO.NET 2 February 21st, 2006 01:55 AM
Chapter-13-direct SQL command-ExecuteNonQuery erro lionking BOOK: Beginning ASP.NET 1.0 3 May 13th, 2004 10:42 PM
Chapter-13-direct SQL command-ExecuteNonQuery erro softdev BOOK: Beginning ASP.NET 1.0 6 February 22nd, 2004 07:55 PM
OleDbCommand.ExecuteNonQuery(); kaz VS.NET 2002/2003 1 December 7th, 2003 04:29 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.