Subject: Filling out DataSet from Datagrid
Posted By: MAKO Post Date: 5/12/2006 10:55:51 AM
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"
Reply By: ColdFusion Reply Date: 5/13/2006 7:05:20 AM
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.

Reply By: rumbafum Reply Date: 5/13/2006 8:15:01 AM
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...


Go to topic 44208

Return to index page 288
Return to index page 287
Return to index page 286
Return to index page 285
Return to index page 284
Return to index page 283
Return to index page 282
Return to index page 281
Return to index page 280
Return to index page 279