将数据从下拉菜单写入表格 [英] Writing data from dropdown menues to table

查看:74
本文介绍了将数据从下拉菜单写入表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们.
我在最后一页遇到了一个问题,我从下拉菜单中获取整数信息,这些下拉菜单又链接到它们自己的数据源.
然后将这些整数插入到与它们来自的表具有相同类型(int)的不同表中,即使那样,我也会在参数期间将它们更改为字符串:

hi guys.
bit of a problem i have come across on my final page, i am taking information which are integers from drop down menus which are, in turn linked to their own data sources.
and then writing these intergers to a different table which are the same types (int) as the tables they are coming from, even then i am changing them to strings during the parameter:

<pre lang="cs">protected void confirmFixedHolButton0_Click(objectsender, EventArgs e)
        {
            using (conn)
            {
                conn.Open();
                SqlCommand insertHolBooking = new SqlCommand("INSERT INTO [HolidayBooking] ([Customer ID], [Fixed Holiday ID], [Holiday ID], [Flight ID], [Holiday Tour ID])
 VALUES 
(@customerID, @fixHolID, @holID, @flightID, @holTourID)", conn);
                insertHolBooking.CommandType = CommandType.Text;

                insertHolBooking.Parameters.AddWithValue("@customerID", customerIDDDM.SelectedItem.ToString());
                insertHolBooking.Parameters.AddWithValue("@fixHolID", fixedHolDDL.SelectedItem.ToString());
                insertHolBooking.Parameters.AddWithValue("@holID", holidayIDDDM.SelectedItem.ToString());
                insertHolBooking.Parameters.AddWithValue("@flightID", flightIDDDM.SelectedItem.ToString());
                insertHolBooking.Parameters.AddWithValue("@holTourID", tourIDDDM0.SelectedItem.ToString());

                try
                {   conn.Open();
                    insertHolBooking.ExecuteNonQuery();
                    Response.Redirect("Bookings.aspx");
                }
                catch (Exception)
                {   Response.Write("<b>Failed please try again.</b>");
                }
            }
        }




它总是抛出错误消息,看不到SQL或参数有任何问题.

正在将此信息写入的表允许为空,所以我看不到问题...

请帮助大家
问候
Matt.




it always throws the error message, cant see anything wrong with the SQL nor with the parameter.

The table this information is being written to is allowing nulls so i cant see the problem...

please help guys
Regards
Matt.

推荐答案

解决了,我重复了conn.Open();.在Using()语句中两次

谢谢大家,很抱歉浪费您的时间

问候
马特.
Solved, i repeated the conn.Open(); twice in the Using() statement

thanks guys, sorry for wasting ur time

Regards
Matt.


这篇关于将数据从下拉菜单写入表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆