|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
INSERT INTOI am tryng to insert a row into an SQL 2005 database, but it is not working. I am not getting an error messsage, rather it is just not adding the row. I have added the Data Source and made the database connection. What am I doing wrong? My code is below. TIA Roy using System; using System.Data; using System.Data.Common; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Text; namespace testing { class Class1 { [STAThread] static void Main(string[] args) { int lnSOBN = 900; int lnBN1 = 188; string strConnection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\royDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; SqlConnection conn = new SqlConnection(strConnection); string strInsert = "INSERT INTO [tblRoy ] (SOBN, BN1) VALUES (@par0, @par1) "; SqlCommand cmd = new SqlCommand(strInsert, conn); SqlParameter parameter1 = new SqlParameter("@par0", SqlDbType.Int, 32); SqlParameter parameter2 = new SqlParameter("@par1", SqlDbType.Int, 32); parameter1.Value = lnSOBN; parameter2.Value = lnBN1; cmd.Parameters.Add(parameter1); cmd.Parameters.Add(parameter2); cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); } } } Hm... I just tested the code and it worked fine here.. What are you using to
verify no data is getting inserted? -- Regards, Jeff Papiez SQL Server 2005 Upgrade Advisor Team -- This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm. Hi Jeff,
I do not know SQL that well. I am using Database Explorer where I have a connection to my royDB.mdf database. What are you checking it with? Roy Show quote "Jeff Papiez [MSFT]" <jpap***@online.microsoft.com> wrote in message news:efscApx5FHA.884@TK2MSFTNGP14.phx.gbl... > Hm... I just tested the code and it worked fine here.. What are you using > to verify no data is getting inserted? > > > -- > Regards, > > Jeff Papiez > SQL Server 2005 Upgrade Advisor Team > -- > This posting is provided "AS IS" with no warranties, and confers no > rights. > Use of included script samples are subject to the terms specified at > http://www.microsoft.com/info/cpyright.htm. > > Roy Gourgi (ro***@videotron.ca) writes:
> I do not know SQL that well. I am using Database Explorer where I have a With SQL 2005 the natural choice would be Management Studio, unless you> connection to my royDB.mdf database. What are you checking it with? have the Express Edition. Express only comes with command-line tools, but there is a preview version of Mgmt Studio for Express available for download at microsoft.com. -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx |
|||||||||||||||||||||||