all groups > sql server programming > november 2005 >
You're in the

sql server programming

group:

INSERT INTO


Re: INSERT INTO Jeff Papiez [MSFT]
11/11/2005 3:47:15 PM
sql server programming:
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.

INSERT INTO Roy Gourgi
11/11/2005 6:34:17 PM
Hi,

I 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();

}

}

}

Re: INSERT INTO Roy Gourgi
11/11/2005 11:25:56 PM
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

[quoted text, click to view]

Re: INSERT INTO Erland Sommarskog
11/12/2005 11:46:56 PM
Roy Gourgi (royng@videotron.ca) writes:
[quoted text, click to view]

With SQL 2005 the natural choice would be Management Studio, unless you
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, esquel@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
AddThis Social Bookmark Button