میشه کمک منید نمیدونم چرا از این قسمت کد ارور میگیره:
adapter.InsertHandbagMen(Item, Price, Discription, dt, catid, Color);
اینم آرگومانهای تیبل :
[Id] INT IDENTITY (1, 1) NOT NULL,
[Item] INT NOT NULL,
[Price] INT NOT NULL,
[Discription] NVARCHAR (MAX) NOT NULL,
[Date] DATE NOT NULL,
[Color] NVARCHAR (50) NOT NULL,
[Photo] NVARCHAR (MAX) NOT NULL,
[Cat] TINYINT NULL,
اینم کل کدی که نوشتم :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace WebApplication3
{
public partial class Managment_Men : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblError.Visible = true;
btnContinue.Visible = false;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (PhotoUpload.HasFile)
{
if (!CheckFileType(PhotoUpload.FileName))
{
lblError.Text += "<br />" + "File Is Not Curect";
}
else if (!CheckFileSize(PhotoUpload))
{
lblError.Text += "<br />" + "Size File Over 1MG ";
}
else
{
Random rnd = new Random();
int Item, Price;
Item = Convert.ToInt32(TextBox1Item.Text);
Price = Convert.ToInt32(TextBox2Price.Text);
TextBox1Item.Text = Item.ToString();
TextBox2Price.Text = Price.ToString();
string Discription, Color;
if (TextBox3Discription.Text.Trim().Length >= 50) Discription = TextBox3Discription.Text.Trim().Substring(0, 50);
else Discription = TextBox3Discription.Text.Trim();
if (TextBox4Color.Text.Trim().Length >= 50) Color = TextBox4Color.Text.Trim().Substring(0, 50);
else Color = TextBox4Color.Text.Trim();
byte catid = Convert.ToByte(DropDownList2.SelectedValue.ToString());
string fileName = Path.GetFileNameWithoutExtension(PhotoUpload.FileName) +
rnd.Next(1000, 10000).ToString();
string ext = Path.GetExtension(PhotoUpload.FileName);
fileName = fileName + ext;
DateTime dt = DateTime.Now;
DataSetTableAdapters.Handbag_MenTableAdapter adapter = new
DataSetTableAdapters.Handbag_MenTableAdapter();
adapter.InsertHandbagMen(Item, Price, Discription, dt, catid, Color);
PhotoUpload.PostedFile.SaveAs(MapPath("~/Photos/" + fileName));
lblResult.Visible = true;
btnContinue.Visible = true;
btnSubmit.Enabled = false;
}
}
else if (!PhotoUpload.HasFile || TextBox1Item.Text == "" || TextBox2Price.Text == ""
|| TextBox3Discription.Text == "" || TextBox4Color.Text == "")
{
lblError.Text += "<br />" + "Pleas Complet Information";
btnContinue.Visible = true;
btnSubmit.Enabled = false;
}
}
bool CheckFileType(string fileName)
{
string ext = Path.GetExtension(fileName);
switch (ext.ToLower())
{
case ".gif": return true;
case ".png": return true;
case ".jpg": return true;
case ".jpeg": return true;
default: return false;
}
}
bool CheckFileSize(FileUpload fileName)
{
if (fileName.PostedFile.ContentLength >= Math.Pow(2, 20)) return false;
else return true;
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("~/Managment-Men.aspx");
}
protected void btnContinue_Click(object sender, EventArgs e)
{
TextBox1Item.Text = string.Empty;
TextBox2Price.Text = string.Empty;
TextBox3Discription.Text = string.Empty;
TextBox4Color.Text = string.Empty;
lblError.Text = string.Empty;
btnSubmit.Enabled = true;
lblResult.Visible = false;
}
}
}
چه اروری میده ؟
کدا خط ارور میده ؟
adapter.InsertHandbagMen(Item, Price, Discription, dt, Color,fileName, catid);
متغیر dt از نوع DateTime است باید به String تبدیل شود:
dt.ToString();
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)