Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design 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 October 20th, 2005, 01:02 PM
Authorized User
 
Join Date: Oct 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reading webcontrols

I have a delema. I have 2 versions of my project. Version one works properly, but it doesn't allow me to use my sql parameter read from the querystring. The second uses the parameters correctly but doesn't read the textboxs and radiobuttonlists from the datagrid.
I will post only the second code. The only difference in the code is that I am using "System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();" instead of a SqlDataAdapter.

I am getting the same look to the datagrid either way. And even with the second set of code I am writing all of the columns to the database correctly with the exception of the textbox and the radiobutton list. Any ideas?

Here is the code. It isn't as complicated as it looks.

<code>
string Set_Name;
    string ConnectionString = "server=edev03;database=on_track;user id=johnrose; password=jrontrack";

      void Page_Load(object sender, EventArgs e)
            {


            DataGrid1.DataSource = MyQueryMethod(Set_Name);
            DataGrid1.DataBind();

            }


    //
        System.Data.DataSet MyQueryMethod(string Set_Name) {
            string connectionString = "server=\'edev03\'; user id=\'johnrose\'; password=\'jrontrack\'; database=\'on_track\'";
            System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionStri ng);

            string queryString = "SELECT smile_data.qsect_key, smile_data.ques_id, smile_data.esetq_id, smile_data.Ques_Order, smile_data.Q_Section, smile_data.Q_Text FROM Smile_Data WHERE Smile_Data.Set_Name=@Set_Name ORDER BY Smile_Data.Set_Name, Smile_Data.Sect_Order, Smile_Data.Ques_Order";
            System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
            dbCommand.CommandText = queryString;
            dbCommand.Connection = dbConnection;

            System.Data.IDataParameter dbParam_Set_Name = new System.Data.SqlClient.SqlParameter();
            dbParam_Set_Name.ParameterName = "@Set_Name";
            dbParam_Set_Name.Value = Request.QueryString["@Set_Name"];
            dbParam_Set_Name.DbType = System.Data.DbType.String;
            dbCommand.Parameters.Add(dbParam_Set_Name);

            System.Data.IDbDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter();
            dataAdapter.SelectCommand = dbCommand;
            System.Data.DataSet dataSet = new System.Data.DataSet();
            dataAdapter.Fill(dataSet);

            return dataSet;
        }

     public void Button_SubmitOrder_Click(object sender, EventArgs e)
                   {

                       foreach(DataGridItem dgi in DataGrid1.Items)
                       {

 string In_Response = ((TextBox)dgi.Cells[4].FindControl("Response")).Text;
    string In_Rating = ((RadioButtonList)dgi.Cells[3].FindControl("GRID_RadioButtonList")).SelectedValu e;

    string In_SectionKey = dgi.Cells[7].Text;
    string In_EQID = dgi.Cells[5].Text;
    string In_QID = dgi.Cells[6].Text;
    string In_HeldKey = Request.QueryString["HeldKey"];
    string In_StudentID = Request.QueryString["StudentID"];



    SqlConnection myConnection = new SqlConnection(ConnectionString);
    SqlCommand UpdateCommand = new SqlCommand();
    UpdateCommand.Connection = myConnection;

    UpdateCommand.CommandText = "INSERT INTO Smile_Results(Section_ID, Response, Rating, ESetQ_ID, Question_ID, Held_Key, Student_ID) VALUES (@Q_SectionKey, @Response, @Rating, @EQID, @QID, @HeldKey, @Student_ID)";

    UpdateCommand.Parameters.Add("@Response", SqlDbType.VarChar, 150).Value = In_Response;
    UpdateCommand.Parameters.Add("@Rating", SqlDbType.VarChar, 150).Value = In_Rating;
     UpdateCommand.Parameters.Add("@Q_SectionKey", SqlDbType.VarChar, 50).Value = In_SectionKey;
    UpdateCommand.Parameters.Add("@EQID", SqlDbType.VarChar, 50).Value = In_EQID;
    UpdateCommand.Parameters.Add("@QID", SqlDbType.VarChar, 50).Value = In_QID;
    UpdateCommand.Parameters.Add("@HeldKey", SqlDbType.VarChar, 50).Value = In_HeldKey;
    UpdateCommand.Parameters.Add("@Student_ID", SqlDbType.VarChar, 50).Value = In_StudentID;
                            // execute the command
                             try {
                                 myConnection.Open();
                                 UpdateCommand.ExecuteNonQuery();
                             }
                             catch (Exception ex) {
                                 Message.Text = ex.ToString();
                             }
                             finally {
                                 myConnection.Close();
                             }




                       }
                   }
</code>







Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass WebControls as struct to BLL instead of indiv rlb ASP.NET 2.0 Professional 3 April 23rd, 2007 03:35 PM
WebControls.LinkButton Ric_H ASP.NET 2.0 Basics 1 January 28th, 2006 08:00 AM
Assign events to webcontrols through XML and XSLT Navas Classic ASP XML 0 November 12th, 2003 05:41 PM





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