我对提交脚本有疑问..请帮忙看看并帮助解决。 [英] I am issue with my submission script.. kindly help take a look at it and Help resolve.

查看:64
本文介绍了我对提交脚本有疑问..请帮忙看看并帮助解决。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class Default7 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
         if (!FileUpload1.HasFile) //Validation
        {
            Response.Write("No file Selected"); return;
        }
        else
        {
            string filename = FileUpload1.PostedFile.FileName;

            //convert the image into the byte
            byte[] imageByte = System.IO.File.ReadAllBytes(filename);

            //Insert the Data in the Table
            using (SqlConnection connection = new SqlConnection())
            {
 connection.ConnectionString = ConfigurationManager.ConnectionStrings["lateefconnectionstring"].ToString();

  connection.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = connection;

                string commandText = "Insert into users values (@Surname,@Lastame,@username,@Phone,@image,getdate,@Department())";


                cmd.CommandText = commandText;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add("@Surname", SqlDbType.VarChar);
                cmd.Parameters["@Surname"].Value = TxtSurname.Text;
                cmd.Parameters.Add("@Lastame", SqlDbType.VarChar);
                cmd.Parameters["@Lastame"].Value = TxtLastName.Text;
                cmd.Parameters.Add("@username", SqlDbType.VarChar);
                cmd.Parameters["@username"].Value = TxtUsername.Text;
                cmd.Parameters.Add("@Phone", SqlDbType.VarChar);
                cmd.Parameters["@Phone"].Value = TxtPhone.Text;
                cmd.Parameters.Add("@image", SqlDbType.VarBinary);
                cmd.Parameters["@image"].Value = imageByte;
                cmd.Parameters.Add("@Department", SqlDbType.VarChar);
                cmd.Parameters["@Department"].Value = TxtDpt.Text;
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                connection.Close();

                Response.Write("Data has been Added");
            }
        }
    }
    }







运行此脚本后我得到以下错误,请帮助我调查一下。






I get this below error after running this script kindly help me look into it.

Incorrect syntax near '('. 
   
 
 Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '('.
 
Source Error: 
 

 
Line 53:                 cmd.Parameters.Add("@Department", SqlDbType.VarChar);
Line 54:                 cmd.Parameters["@Department"].Value = TxtDpt.Text;
Line 55:                 cmd.ExecuteNonQuery();  
Line 56:                 cmd.Dispose();  
Line 57:                 connection.Close(); 

推荐答案

查看你的代码:

Look at your code:
string commandText = "Insert into users values (@Surname,@Lastame,@username,@Phone,@image,getdate,@Department())";

你为什么试图插入函数?

尝试删除括号:

Why are you trying to INSERT to a function?
Try removing the brackets:

string commandText = "Insert into users values (@Surname,@Lastame,@username,@Phone,@image,getdate,@Department)";


这篇关于我对提交脚本有疑问..请帮忙看看并帮助解决。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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