bftarane
یک شنبه 14 مهر 1392, 09:39 صبح
سلام.
آیا در Access مثل Sql Server میشه یه یه فیلد خاصیت null داد؟
راستش من نگاه کردم یه خاصیت به اسم Required وجود داشت که فکر کردم باید معادل همون null در Sql Server باشه ولی نمی دونم چرا جواب نداد.
من یه مقدار از نوع number دارم که Required اش رو هم NO گذاشتم که ورودیش رو از تکست باکس می گیرم (با Asp.net کار می کنم) که وقتی تکست باکس خالی باشه خطا می ده که البته این رو از درون کد هندل کردم. ولی خوب انتظار داشتم با همون ست کردن Required به No خطایی دریافت نکنم.
لطفاً راهنمایی کنید.
niusha_amir
یک شنبه 14 مهر 1392, 19:55 عصر
سلام
فیلد required به معنی "الزامی بودن" است و اگر مقدار آن را yes بگذارید یعنی هنگام ورود هیچگاه نباید خالی رد کنید یا به عبارتی هیچگاه نباید null باشد و فکر کنم شما برعکس عمل کردید با انتخاب no یعنی این الزام برداشته شده و کاربر می تواند این فیلد را خالی رد کند
mazoolagh
دوشنبه 15 مهر 1392, 10:36 صبح
اگر از dataset استفاده کردین باید در خود dataset designer هم ویژگیهای فیلد رو بررسی و اینها رو چک کنین:
1- allowdbnull که مشخصه چی هست و باید true باشه
2- nullvalue که نباید throw exception باشه
احتمالا همین مورد 2 باشه
bftarane
دوشنبه 15 مهر 1392, 20:06 عصر
نه از دیتاست استفاده نکرده بودم.
ممنون از پاسخ های دوستان.
اینم کدهایی که استفاده کردم
int porsant = 0;
int hoghogh = 0;
if (txt_hoghogh.Text != string.Empty)
{
hoghogh = Convert.ToInt32(txt_hoghogh.Text);
}
if (txt_porsant.Text != string.Empty)
{
porsant = Convert.ToInt32(txt_porsant.Text);
}
OleDbConnection con = new OleDbConnection();
OleDbCommand com = new OleDbCommand();
Class1 cls = new Class1();
con.ConnectionString = cls.PRV1();
com = con.CreateCommand();
com.CommandText = "insert into registers([name],famili,mcode,address,tell,[user],pass,Bank,AccountNumber,CreditCard,bdata,tahsilat ,tahol,activiti,porsant,hoghogh,mazaya,mobile,moat ef,garantie,mail) " +
"values('" + Txt_name.Text + "','" + txt_famili.Text + "','" + txt_mcode.Text + "','" + txt_address.Text + "','" +
txt_tell.Text + "','" + txt_user.Text + "','" + txt_pass.Text + "','" + txt_bank.Text + "','" + txt_accuntno.Text +
"','" + txt_CreditCard.Text + "','" + txt_bdata.Text + "','" + txt_tahsilat.Text + "'," + rbl_tahol.SelectedItem.Value + ",'" + txt_activiti.Text + "'," + porsant + "," + hoghogh + ",'" + txt_mazaya.Text + "','" + txt_mobile.Text + "','" + txt_moatef.Text + "','" + txt_garantie.Text + "','" + txt_mail.Text + "')";
if (txt_pass.Text == txt_retypeuser.Text)
{
con.Open();
com.ExecuteNonQuery();
con.Close();
mazoolagh
سه شنبه 16 مهر 1392, 11:01 صبح
بجای اینکه مقادیر رو مستقیما در insert command بگذارین اونها رو بصورت پارامتر پاس کنین :
com.CommandText = "insert into registers([name],famili, ...) VALUES @name, @famili,...)
و موقع پاس کردن مقادیر چک کنین که اگر محتوای فیلد خالی هست بجاش dbnull پاس بشه:
com.parameters.add("@name",...).value = stringisnullorempty(Txt_name.Text) ? dbnull.value : Txt_name.Text ;
ادامه بحث هم اگر لازم شد در بخش asp.net
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.