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>
|