PDA

View Full Version : مبتدی: با سلام اشکال این کد برای درج یک کتاب چیست ؟ ممنون



mirhosseini-2014
شنبه 08 شهریور 1393, 16:15 عصر
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.IO;
using System.Drawing.Imaging;
using System.Data;
using System.Drawing;
using System.Security.Principal;




namespace WebApplication1
{
public partial class WebForm10 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] != null)
{
string user = (string)(Session["user"]);


}



}


protected void Button3_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
string FileNamebook = Path.GetFileName(FileUpload1.PostedFile.FileName);


//Save files to disk
FileUpload1.SaveAs(Server.MapPath("book_file/" + FileNamebook));


if (FileUpload2.PostedFile != null)
{
string FileNameimage = Path.GetFileName(FileUpload2.PostedFile.FileName);


//Save files to disk
FileUpload2.SaveAs(Server.MapPath("book_image/" + FileNameimage));


//Add Entry to DataBase


SqlConnection conn = new SqlConnection();

conn.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\M e\Documents\Visual Studio 2012\Projects\WebApplication1\WebApplication1\App_ Data\project.mdf;Integrated Security=True;Connect Timeout=30";



string strQuery = "insert into book (book_name,author,book_subject,book_group, publications,publication_year, description,bfile_name,bfile_path,bimage_name,bima ge_path,active,upload_date,user_name)" + " values(@book_name,@author,@book_subject,@book_grou p, @publications,@publication_year, @description,@bfile_name,@bfile_path,@bimage_name, @bimage_path,@active,@upload_date,@user_name)";

SqlCommand comm = new SqlCommand(strQuery);




comm.Parameters.AddWithValue("@book_name", TextBox1.Text);


comm.Parameters.AddWithValue("@author", TextBox2.Text);


comm.Parameters.AddWithValue("@book_subject", TextBox3.Text);




comm.Parameters.AddWithValue("@book_group", DropDownList1.SelectedItem.Text);


comm.Parameters.AddWithValue("@publications", TextBox4.Text);


comm.Parameters.AddWithValue("@publication_year", TextBox5.Text);


comm.Parameters.AddWithValue("@description", TextBox6.Text);


comm.Parameters.AddWithValue("@bfile_name", FileNamebook);


comm.Parameters.AddWithValue("@bfile_path", "book_file/" + FileNamebook);


comm.Parameters.AddWithValue("@bimage_name", FileNameimage);


comm.Parameters.AddWithValue("@bimage_path", "book_image/" + FileNameimage);


comm.Parameters.AddWithValue("@active", false);


comm.Parameters.AddWithValue("@upload_date", System.DateTime.Now.ToShortDateString());
comm.Parameters.AddWithValue("@user_name", User);










comm.CommandType = CommandType.Text;
comm.Connection = conn;
try
{
conn.Open();
comm.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
conn.Close();
conn.Dispose();
}
}
}


TextBox1.Text = "";
TextBox2.Text = "";


TextBox3.Text = "";
DropDownList1.SelectedIndex = 0;


TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";












}




}
}



خطایی که می دهد
No mapping exists from object type System.Security.Principal.WindowsPrincipal to a known managed provider native type.با سپاس