本文介绍了无法调试C#脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以查看我下面的代码,并就可能出现的问题向我提出建议吗? 基本上,我按F11启动脚本,打开浏览器窗口,我从下拉菜单中做出一些选择,然后我收到错误。 

Can someone take a look at my code below and give me a suggestion as to what could be wrong?  Basically, I hit F11 to start the script, a browser window opens, I make some selections from from drop downs, and then I get an error. 

'写入数据库时​​出现问题! 请检查你的连接字符串!!'¥b $ b

'There was an issue writing to the database!  Please check your connection string!!'




我正在使用C#和ASP.NET。

I am using C# and ASP.NET.

我似乎无法调试这个,所以我不知道这里发生了什么。

I can't seem to debug this so I can't tell what is going on here.




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;


namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        protected void Button1_Click(object sender, EventArgs e)
        {

            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\rshuell001\Desktop\4_Web_Solution\Risk_DB.mdb";
            string rc_Name = DropDownList1.SelectedItem.Text;
            string L1 = DropDownList2.SelectedItem.Text;
            string L2 = DropDownList3.SelectedItem.Text;
            string L3 = DropDownList4.SelectedItem.Text;
            string TheLevel = DropDownList5.SelectedItem.Text;
            string Severity = DropDownList6.SelectedItem.Text;

            string driver1 = TextBox1.Text.Trim();
            string driver2 = TextBox2.Text.Trim();
            OleDbCommand cmd = new OleDbCommand(@"INSERT INTO tbl_IHC_Risk_Card (rc_Name, L1, L2, L3, TheLevel, Severity, driver1, driver2) VALUES (@rc_Name, @L1, @L2, @L3, @TheLevel, @Severity, @driver1, @driver2)")
            {
                Connection = conn
            };

            conn.Open();

            if (conn.State == ConnectionState.Open)
            {
                // you should always use parameterized queries to avoid SQL Injection
                cmd.Parameters.Add("@rc_Name", OleDbType.VarChar).Value = rc_Name;
                cmd.Parameters.Add("@L1", OleDbType.VarChar).Value = L1;
                cmd.Parameters.Add("@L2", OleDbType.VarChar).Value = L2;
                cmd.Parameters.Add("@L3", OleDbType.VarChar).Value = L3;
                cmd.Parameters.Add("@TheLevel", OleDbType.VarChar).Value = TheLevel;
                cmd.Parameters.Add("@Severity", OleDbType.VarChar).Value = Severity;

                cmd.Parameters.Add("@driver1", OleDbType.VarChar).Value = TextBox1.Text;
                cmd.Parameters.Add("@driver2", OleDbType.VarChar).Value = TextBox2.Text;

                try
                {
                    cmd.ExecuteNonQuery();
                    Type cstype = this.GetType();

                    // Get a ClientScriptManager reference from the Page class.
                    ClientScriptManager cs = Page.ClientScript;

                    // Check to see if the startup script is already registered.
                    if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
                    {
                        String cstext = "alert('Data Added to Database!!');";
                        cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
                    }

                    conn.Close();
                }
                catch (OleDbException ex)
                {

                    Type cstype = this.GetType();
                    ClientScriptManager cs = Page.ClientScript;

                    // Check to see if the startup script is already registered.
                    if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
                    {
                        String cstext = "alert('There was an issue writing to the database!  Please check your connection string!!')";
                        cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
                    }
                    conn.Close();
                }
            }
            else
            {

            }

        }
    }
}










MY BOOK

推荐答案


这篇关于无法调试C#脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 04:41