hello
iam trying to add more thank one filed but i get error
foreach (ListItem lst in test_names.Items)
{
if (lst.Selected)
{
string selectedValue = lst.Value;
string patient_id = Request.QueryString["id"];
SqlConnection cnm = new SqlConnection(ConfigurationManager.ConnectionStrings["lap_connection"].ConnectionString);
SqlCommand cmd = new SqlCommand("INSERT INTO [patient_test_data] (test_id,test_date,pat_id) VALUES ('" + selectedValue + "','" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + patient_id + "');", cnm);
cmd.Connection = cnm;
cmd.CommandType = CommandType.Text;
cnm.Open();
cmd.ExecuteScalar();
cnm.Close();
ScriptManager.RegisterStartupScript(this, this.GetType(), "show_error", "showSuccess('Test Has Been Added Successfully',2000);", true);
}
}
this is the error that i got
There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
i don't know how to insert with this function
OMG is it me :@ let me kill my self OMG !!!! how the hell i didn't see this -_- thanks BTW so let us go to the next step
now i want to create a daynamic control 3 label and 3 textbox depended on value comes from sql data reader "number of columns"
this is my code
<pre lang="c#">cn = new SqlConnection(ConfigurationManager.ConnectionStrings["lap_connection"].ConnectionString);
cmd = new SqlCommand("SELECT COUNT( pat_id) AS patient_test FROM patient_test_data WHERE dbo.patient_test_data.test_date >= cast(getdate() as Date) AND dbo.patient_test_data.pat_id = 4;", cn);
cmd.CommandType = CommandType.Text;
cmd.Connection.Open();
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (dr.Read())
{
int number_test = int.Parse(dr["patient_test"].ToString());
for (int number = int.Parse(dr["patient_test"].ToString()); number <= number_test; number++)
{
TextBox txt = new TextBox();
TextBox txt2 = new TextBox();
TextBox txt3 = new TextBox();
this.Controls.Add(txt);
this.Controls.Add(txt2);
this.Controls.Add(txt3);
}
}
i just i don't know i got this error Collection was modified; enumeration operation may not execute.
thanks in advanced