473,508 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding a row

Hi,

I am trying to add a row to my database. I first made a data connection with
Database Explorer where I have made the connection to my database royDBnew
and my table tblRoy with 2 columns SOBN, BN1 (both int). Then I made a data
source connection in the Data Sources. When I run the program I do not get
any errors, but it does not seem to add the row into my table. When I check
in the Database Explorer in my tblRoy it has not added the row. What am I
doing wrong. Below is my code.

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=|DataDirector y|\royDBnew.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, 255);

SqlParameter parameter2 = new SqlParameter("@par1", SqlDbType.Int, 255);

parameter1.Value = lnSOBN;

parameter2.Value = lnBN1;

cmd.Parameters.Add(parameter1);

cmd.Parameters.Add(parameter2);

cmd.Connection.Open();

cmd.ExecuteNonQuery();

cmd.Connection.Close();

}

}

}

Thanks

Roy
Nov 17 '05 #1
1 1171
maybe your int size? but I don't see how this would be the problem cause I
would figure an error would bounce back if it was a problem. Maybe someone
else sees something more obvious. I think an int is sized as 4, although I
have put in 0 without issues, too.

Unless SqlExpress does things differently. I'm not familiar with this, nor
how AttachDbFilename works within a conn string.

"Roy Gourgi" <ro***@videotron.ca> wrote in message
news:kZ********************@weber.videotron.net...
Hi,

I am trying to add a row to my database. I first made a data connection
with Database Explorer where I have made the connection to my database
royDBnew and my table tblRoy with 2 columns SOBN, BN1 (both int). Then I
made a data source connection in the Data Sources. When I run the program
I do not get any errors, but it does not seem to add the row into my
table. When I check in the Database Explorer in my tblRoy it has not added
the row. What am I doing wrong. Below is my code.

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=|DataDirector y|\royDBnew.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, 255);

SqlParameter parameter2 = new SqlParameter("@par1", SqlDbType.Int, 255);

parameter1.Value = lnSOBN;

parameter2.Value = lnBN1;

cmd.Parameters.Add(parameter1);

cmd.Parameters.Add(parameter2);

cmd.Connection.Open();

cmd.ExecuteNonQuery();

cmd.Connection.Close();

}

}

}

Thanks

Roy

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2402
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1...
10
2661
by: sp0 | last post by:
Is there a reason why to make mix numbers improper when adding? It seems when subtracting and adding, adding a subtracting the whole numbers and fraction parts should be sufficient? what'ch think
1
4457
by: hzgt9b | last post by:
When adding my VB .NET solution (with two sub-projects) the folder structure in VSS gets an extra level of folders... For example, here's the structure of the solution on my C:\...
3
4856
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
1936
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
0
1863
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
1
2018
by: seanmayhew | last post by:
I have a form page that that while editing saves the data to an xml doc before submitting to db. On each page unload it saves the xmldoc as the user can add multiple items to the company like...
6
2656
by: vb | last post by:
Hi, I am new to .Net. I am using a Combo Box in my windows forms. I am adding the items by creating the instances and adding the same to the list. My questions/doubts are: 1. If I have 25 to...
9
4467
by: Kadett | last post by:
Hi all, I have following problem: I'm creating a ListView (Details) control at run-time and filling it with some records (let's say 10 000). This operation seems to be quite fast, but when I call...
0
1404
by: AndyL69 | last post by:
Hello I've got a very strange Problem. When im adding a new ACE entry to a UNC Direcotry the inherented ACL's will be lost. When I'm adding a new ACE to a directory / file in this UNC path the...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.