Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 20th, 2005, 03:03 AM
Authorized User
 
Join Date: Aug 2005
Location: , , Finland.
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)
      Page.Validate()
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")
loConn.Open()
cmdInsert.ExecuteNonQuery()
loConn.Close()
UDIDS = cmdInsert.Parameters("@UDID").Value
response.redirect("regsuccess.aspx")
    else
end if
    end if
end sub

</script>

Reply With Quote
  #2 (permalink)  
Old September 20th, 2005, 10:03 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:40 AM.


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