2016-10-18 21 views
-1

次のコードを使用してSQLサーバーにデータを挿入しますが、データは挿入されません。対応するフォルダ。C#を使用してSQL Serverにデータを挿入したい

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

public partial class company_add : System.Web.UI.Page 
{ 
    string strConnString = ConfigurationManager.ConnectionStrings["JobInnConnectionString1"].ConnectionString; 
    string s1; 
    string s2; 
    string path1; 
    string path2; 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 

    protected void SubmitCompany_Click(object sender, EventArgs e) 
    { 
     if (companylogo.PostedFile.ContentLength > 0) 
     { 
      s1 = Path.GetFileName(companylogo.FileName); 
      path1 = Server.MapPath("Logo") + "/" + s1; 
      companylogo.SaveAs(path1); 
     } 
     if (cover_img_file.PostedFile.ContentLength > 0) 
     { 
      s2 = Path.GetFileName(cover_img_file.FileName); 
      path2 = Server.MapPath("cover_images") + "/" + s2; 
      cover_img_file.SaveAs(path2); 
     } 
     SqlConnection con = new SqlConnection(strConnString); 
     con.Open(); 
     SqlCommand com = new SqlCommand("insertinto_company", con); 
     com.CommandType = CommandType.StoredProcedure; 
     com.Connection = con; 

     com.Parameters.AddWithValue("@Logo", s1); 
     com.Parameters.AddWithValue("@Company_Name", companyname.Text.Trim()); 
     com.Parameters.AddWithValue("@Headline", headline.Text.Trim()); 
     com.Parameters.AddWithValue("@Short_Description", shortdescription.Text.Trim()); 
     com.Parameters.AddWithValue("@Location", location.Text.Trim()); 
     com.Parameters.AddWithValue("@Employer", DropDownListemployer.SelectedValue.Trim()); 
     com.Parameters.AddWithValue("@Website_Address", webadres.Text.Trim()); 
     com.Parameters.AddWithValue("@Founded_on", foundedon.Text.Trim()); 
     com.Parameters.AddWithValue("@Phone_no", phoneno.Text.Trim()); 
     com.Parameters.AddWithValue("@Email", TextEmail.Text.Trim()); 
     com.Parameters.AddWithValue("@cover_image", s2); 
     com.Parameters.AddWithValue("@facebook_Url", facebuk_url.Text.Trim()); 
     com.Parameters.AddWithValue("@Twitter_Url", twitter_url.Text.Trim()); 
     com.Parameters.AddWithValue("@google_url", google_url.Text.Trim()); 
     com.Parameters.AddWithValue("@youtube_url", youtube_url.Text.Trim()); 
     com.Parameters.AddWithValue("@company_detail", company_detail.Text.Trim()); 
    } 
} 
+5

あなたは '.ExecuteNonQuery()'あなたのコマンドにしたいかもしれません不足しています。 –

答えて

11

youreの

com.ExecuteNonQuery(); 
関連する問題