如何使用此功能将数据库插入列表框中的多个项目

如何使用此功能将数据库插入列表框中的多个项目

本文介绍了如何使用此功能将数据库插入列表框中的多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

iam尝试添加更多感谢文件,但我收到错误消息

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

            }
        }




这是我得到的错误

INSERT语句中的列多于VALUES子句中指定的值. VALUES子句中的值数必须与INSERT语句中指定的列数匹配.


我不知道如何使用此功能插入



OMG是我吗:@让我杀死我的自我OMG !!!!我怎么没看到这个-_-谢谢,顺便说一句,让我们继续下一步
现在我想创建一个Daynamic控件3标签和3文本框,取决于值来自sql数据读取器列数"


这是我的代码




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();
                    //txt.Text = dr["Col1"].ToString();
                    TextBox txt2 = new TextBox();
                    //txt2.Text = dr["Col2"].ToString();
                    TextBox txt3 = new TextBox();
                    //txt3.Text = dr["Col3"].ToString();
                    this.Controls.Add(txt);
                    this.Controls.Add(txt2);
                    this.Controls.Add(txt3);
                }
            }



我只是我不知道我收到了这个错误集合已被修改;枚举操作可能无法执行.

谢谢Advanced



i just i don''t know i got this error Collection was modified; enumeration operation may not execute.

thanks in advanced

推荐答案


这篇关于如何使用此功能将数据库插入列表框中的多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 21:10