ASP.NET C#sqlserver2005 [英] Asp.net c# sqlserver2005

查看:71
本文介绍了ASP.NET C#sqlserver2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

namespace photoshops
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            onflbload(sender, e);
        }
        public void onflbload(object sender, EventArgs e)
        {
            // Create a byte[] from the input file
            int len = flbload.PostedFile.ContentLength;
            byte[] pic = new byte[len];
            flbload.PostedFile.InputStream.Read(pic, 0, len);
            // Insert the image and comment into the database
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString =@"Data Source=DEVI\SQLEXPRESS; Initial Catalog =cat; Integrated Security=SSPI";
               
            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("insert into tblphotosettings "
                 + "(BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total ) values (@BillNo,@CustomerName,@Address,@StartDate,@EndDate,@Systemurl,@Numberofcopies,@Amount,@Total)", connection);
                cmd.Parameters.Add("@BillNo", SqlDbType.NVarChar).Value = TextBox1.Text;
                cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar).Value = TextBox2.Text;
                cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = TextBox3.Text;
                cmd.Parameters.Add("@StartDate", SqlDbType.NVarChar).Value = Rdbsdate.SelectedDate;
                cmd.Parameters.Add("@EndDate", SqlDbType.NVarChar).Value = Rdbddate.SelectedDate;
                cmd.Parameters.Add("@Systemurl", SqlDbType.Image).Value = pic;
                cmd.Parameters.Add("@Numberofcopies", SqlDbType.NVarChar).Value = TextBox7.Text;
                cmd.Parameters.Add("@Amount", SqlDbType.NVarChar).Value = TextBox8.Text;
                cmd.Parameters.Add("@Total", SqlDbType.NVarChar).Value = TextBox9.Text;
                cmd.ExecuteNonQuery();
            }
            
            finally
            {
                connection.Close();
            }
        }
    }
}

我的错误图像位置未存储

My error image location not store

推荐答案

您尝试以下代码:-
You try this code:-
namespace photoshops
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            onflbload(sender, e);
        }
        public void onflbload(object sender, EventArgs e)
        {
            // Create a byte[] from the input file
            int len = flbload.PostedFile.ContentLength;
            byte[] pic = new byte[len+1];
            flbload.PostedFile.InputStream.Read(pic, 0, pic.Length);
            // Insert the image and comment into the database
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString =@"Data Source=DEVI\SQLEXPRESS; Initial Catalog =cat; Integrated Security=SSPI";
               
            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("insert into tblphotosettings "
                 + "(BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total ) values (@BillNo,@CustomerName,@Address,@StartDate,@EndDate,@Systemurl,@Numberofcopies,@Amount,@Total)", connection);
                cmd.Parameters.Add("@BillNo", SqlDbType.NVarChar).Value = TextBox1.Text;
                cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar).Value = TextBox2.Text;
                cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = TextBox3.Text;
                cmd.Parameters.Add("@StartDate", SqlDbType.NVarChar).Value = Rdbsdate.SelectedDate;
                cmd.Parameters.Add("@EndDate", SqlDbType.NVarChar).Value = Rdbddate.SelectedDate;
                cmd.Parameters.Add(new SqlParameter("@Systemurl",pic));
                cmd.Parameters.Add("@Numberofcopies", SqlDbType.NVarChar).Value = TextBox7.Text;
                cmd.Parameters.Add("@Amount", SqlDbType.NVarChar).Value = TextBox8.Text;
                cmd.Parameters.Add("@Total", SqlDbType.NVarChar).Value = TextBox9.Text;
                cmd.ExecuteNonQuery();
            }
            
            finally
            {
                connection.Close();
            }
        }
    }
}



如果以上代码不起作用,请尝试以下操作:
您可以尝试以下代码:-



If above code not work then try this:
You try this code:-

namespace photoshops
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            onflbload(sender, e);
        }
        public void onflbload(object sender, EventArgs e)
        {
            // Create a byte[] from the input file
            int len = flbload.PostedFile.ContentLength;
            byte[] pic = new byte[len+1];
            flbload.PostedFile.InputStream.Read(pic, 0, pic.Length);
            // Insert the image and comment into the database
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString =@"Data Source=DEVI\SQLEXPRESS; Initial Catalog =cat; Integrated Security=true";
               
            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("insert into tblphotosettings "
                 + "(BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total ) values (@BillNo,@CustomerName,@Address,@StartDate,@EndDate,@Systemurl,@Numberofcopies,@Amount,@Total)", connection);
                cmd.Parameters.Add(new SqlParameter("@BillNo", TextBox1.Text));
                cmd.Parameters.Add(new SqlParameter("@CustomerName", TextBox2.Text));
                cmd.Parameters.Add(new SqlParameter("@Address", TextBox3.Text));
                cmd.Parameters.Add(new SqlParameter("@StartDate",Rdbsdate.SelectedDate));
                cmd.Parameters.Add(new SqlParameter("@EndDate", Rdbddate.SelectedDate));
                cmd.Parameters.Add(new SqlParameter("@Systemurl",pic));
                cmd.Parameters.Add(new SqlParameter("@Numberofcopies", TextBox7.Text));
                cmd.Parameters.Add(new SqlParameter("@Amount", TextBox8.Text));
                cmd.Parameters.Add(new SqlParameter("@Total", TextBox9.Text));
                cmd.ExecuteNonQuery();
            }
            
            finally
            {
                connection.Close();
            }
        }
    }
}


这篇关于ASP.NET C#sqlserver2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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