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 May 12th, 2006, 10:55 AM
Authorized User
 
Join Date: Feb 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MAKO
Default Filling out DataSet from Datagrid

Hi fellows!

I have a question. When I bind a datagrid's datasource to a table in a DataSet, does the DataSet's table get data as I type new rows in the datagrid? Please, excuse my ignorance, but I've been cheking for hours on a method I wrote to persist data to the database calling stored procedures, but no data is recorded in the db. Help Please!

MAKO - "El super simio"
__________________
MAKO - \"El super simio\"
 
Old May 13th, 2006, 07:05 AM
Authorized User
 
Join Date: May 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to ColdFusion
Default

How I get the data from a dataset:
            CustomerDAL cDAL = new CustomerDAL();
            DataSet ds = cDAL.GetContactPerson(id);
            DataRow dr = ds.Tables[0].Rows[0];

            _PK_ContactPerson = (int)dr["PK_ContactPerson"];
            _FirstName = (String)dr["FirstName"];
            _FirstName = (String)dr["FirstName"];
            _Phone = (String)dr["PhoneNumber"];
            _Fax = (String)dr["FaxNumber"];
            _Email = (String)dr["EmailAdress"];
            _Country = (String)dr["Country"];
            _PostalCode = (String)dr["ZipCode"];
            _City = (String)dr["City"];
            _Street = (String)dr["StreetAdress"];
            _MobilePhoneNumber = (String)dr["MobilePhoneNumber"];
            _Title = (String)dr["Title"];



How I give data to a stored procedure in my database.

        public int CreateContactPerson(int fk_Customer, string firstName,string lastName,string phoneNumber,string mobilePhoneNumber,string faxNumber,string emailAdress,string country,string zipCode,string city,string streetAdress,string title)
        {
            int pkContactPerson=0;

            if(dbConnection.State == ConnectionState.Closed)
                dbConnection.Open();

            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "CreateContactPerson";
            cmd.Connection = dbConnection;

            cmd.Parameters.Add("@FirstName", firstName);
            cmd.Parameters.Add("@LastName", lastName);
            cmd.Parameters.Add("@PhoneNumber", phoneNumber);
            cmd.Parameters.Add("@MobilePhoneNumber", mobilePhoneNumber);
            cmd.Parameters.Add("@FaxNumber", faxNumber);
            cmd.Parameters.Add("@EmailAdress", emailAdress);
            cmd.Parameters.Add("@Country", country);
            cmd.Parameters.Add("@ZipCode", zipCode);
            cmd.Parameters.Add("@City", city);
            cmd.Parameters.Add("@StreetAdress", streetAdress);
            cmd.Parameters.Add("@Title", title);

            SqlParameter param = new SqlParameter();
            param.ParameterName = "@autonum";
            param.SqlDbType = SqlDbType.Int;
            param.Direction = ParameterDirection.Output;
            cmd.Parameters.Add(param);

            cmd.ExecuteNonQuery();
            pkContactPerson = (int)cmd.Parameters["@autonum"].Value;

            if(dbConnection.State == ConnectionState.Open)
                dbConnection.Close();

            return pkContactPerson;
        }


Larege examples maybe ^^
I've never tried to give data to a dataset but seing how none has replied I give you this so you get to see something.

 
Old May 13th, 2006, 08:15 AM
Authorized User
 
Join Date: Apr 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

maybe the question is how you insert new rows in your DataGrid... If you insert new rows in a Dataset and then rebind again your DataGrid all data will be in your DataSet to update...






Similar Threads
Thread Thread Starter Forum Replies Last Post
Filling ComboBox from Dataset dcathers C# 9 June 15th, 2013 03:31 AM
filling of datagrid rahulyadav23 .NET Framework 2.0 2 June 29th, 2005 06:24 AM
filling Dataset with datagrid variables frankv25 ASP.NET 1.0 and 1.1 Professional 1 August 30th, 2004 01:05 PM
filling of dataset abhimca_1 ADO.NET 1 August 6th, 2003 08:23 AM
filling of dataset abhimca_1 ADO.NET 2 August 5th, 2003 03:05 PM





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