Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 January 13th, 2005, 05:34 AM
Registered User
 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Urgent:Need help to INSERT information to database

Im using the Data Access Application Block in my application. I can't insert the information successfully into my sql database. No error message come out. Can anybody give me some opinion on this?


using (SqlConnection conn = new SqlConnection(dbConn) )
{
conn.Open();
using (SqlTransaction trans = conn.BeginTransaction())
{
SqlParameter [] arParms = new SqlParameter[2];
arParms[0] = new SqlParameter("@Ic_No", SqlDbType.VarChar,20,"Customer_Ic_No");
arParms[0].Direction = ParameterDirection.Input;
arParms[0].Value = txtIC.Text;
arParms[1] = new SqlParameter("@Name", SqlDbType.Char, 25,"Customer_Name");
arParms[1].Direction = ParameterDirection.Input;
arParms[1].Value = txtName.Text;
sqllHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "usp_AddCustomerRecord", arParms);
trans.Commit();
}
}

 
Old January 13th, 2005, 08:18 PM
Kep Kep is offline
Authorized User
 
Join Date: Aug 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can't find a version of ExecuteNonQuery that has the parameters you've specified. What type is sqlHelper?

Other than that your code looks fine. Does the stored procedure work when you run it in Query Analyzer?

Kep.
 
Old January 13th, 2005, 08:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Try removing the commandtype.
sqllHelper.ExecuteNonQuery(conn, "usp_AddCustomerRecord", arParms);


======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old January 14th, 2005, 01:44 AM
Registered User
 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Im using the Microsoft Data Access Application Blocks. That's why can use the sqllHelper.ExecuteNonQuery(conn, "usp_AddCustomerRecord", arParms); i have removed the "CommandType.StoredProcedure" in the executeNonQuery... but still no didn't work... I think i didn't connect it to the database... but everything is fine.... below is my sql statement. maybe you all have helped me to have a look.

use Northwind

CREATE PROCEDURE usp_AddCustomerRecord
    (
    @Ic_No varchar(20),
    @Name Char(25)
    ) AS

INSERT INTO CustomerData
    (
    Customer_Ic_No,
    Customer_Name
    )

VALUES
    (
    @Ic_No,
    @Name
    )


 
Old January 14th, 2005, 06:06 AM
Registered User
 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thx guys.... i figured it out myself already.

sqllHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "usp_AddCustomerRecord",

The "conn" should be replaced with the "trans". :)
It works now... :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
information ( urgent ) jameel SharePoint Admin 2 December 7th, 2007 01:58 AM
Urgent Information Required For reporting subhan BOOK: Professional Crystal Reports for VS.NET 1 October 8th, 2005 12:05 PM
Pasting information to a second database Brendan Bartley Access 1 September 27th, 2005 09:45 AM
Connecting login to more database information donthomaso Dreamweaver (all versions) 3 May 9th, 2005 03:28 PM
Failed to load database information r_ganesh76 Crystal Reports 4 October 7th, 2004 03:04 AM





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