PDA

View Full Version : سوال: چرا رکوردهای پایگاه داده من حذف نمی شوند ؟



Alen
دوشنبه 23 شهریور 1388, 11:35 صبح
سلام دوستان
من با استفاده از access 2007 و VB‎‎.Net 2008 کدی برای حذف رکورد های پایگاه داده بصورت زیر نوشته ام




oledbconnection.Open()
oledbcommand.CommandText = "delete from Mojoudi where MojoudiUnit='" + TextBox1.Text.Trim() + "' and MojoudiYear='" + TextBox2.Text.Trim() + "' and MojoudiMounth='" + TextBox3.Text.Trim() + "';"
oledbcommand.ExecuteNonQuery()
oledbconnection.Close()





مشکل اینه که این query از داخل خود access درست عمل میکنه اما اینجا هیچ رکوردی رو حذف نمی کنه
اگه ممکنه منو راهنمایی بفرمایید

amir4_1363
دوشنبه 23 شهریور 1388, 12:04 عصر
دوست عزیز کد زیر را امتحان کن


Dim db As Database
Dim Rs As Recordset
Dim i As Long
Dim RsCount As Long
Set db = CurrentDb
Set Rs = db.OpenRecordset("نام تیبل مربوطه")
'*******************
'*******************
RsCount = Rs.RecordCount
If MsgBox("متن مسیج باکس", vbYesNo + vbQuestion + vbDefaultButton2, "حذف کردن") = vbYes And Rs.EOF = False Then

Rs.MoveFirst
For i = 1 To RsCount
Rs.Edit
Rs.Delete
Rs.MoveNext
Next i

'Me.Requery
Rs.close
Set Rs = Nothing
End If
End Sub

amirzazadeh
دوشنبه 23 شهریور 1388, 13:21 عصر
سلام دوستان
من با استفاده از access 2007 و VB‎‎.Net 2008 کدی برای حذف رکورد های پایگاه داده بصورت زیر نوشته ام




oledbconnection.Open()
oledbcommand.CommandText = "delete * from Mojoudi where MojoudiUnit='" + TextBox1.Text.Trim() + "' and MojoudiYear='" + TextBox2.Text.Trim() + "' and MojoudiMounth='" + TextBox3.Text.Trim() + "';"
oledbcommand.ExecuteNonQuery()
oledbconnection.Close()




مشکل اینه که این query از داخل خود access درست عمل میکنه اما اینجا هیچ رکوردی رو حذف نمی کنه
اگه ممکنه منو راهنمایی بفرمایید
در دستور حذف علامت * رو اضافه كن ببين مشكلت برطرف ميشه.
........................
موفق باشيد

Alen
دوشنبه 23 شهریور 1388, 17:17 عصر
ممنون بچه ها مشکلم حل شد
مشکل از این نکته بود که در Acess 2007 باید برای داشتن کنترل کامل بر روی DB مسیری که DB در اون قرار داره به عنوان یه مسیر trust معرفی بشه به نحو زیر


Specify a trusted location
In the Message Bar, click Options.
At the bottom of the Microsoft Office Security Options dialog box, click Open the Trust Center.
In the left pane of the Trust Center dialog box, click Trusted Locations.
To add a network location, in the right pane, select the Allow Trusted Locations on my network check box.
Click Add new location.
In the Microsoft Office Trusted Location dialog box, do one of the following:
In the Path box, type the full path of the location that you want to add.
Click Browse to browse to the location.
To specify that subfolders of the new trusted locations should also be trusted, select the Subfolders of this location are also trusted check box.
Optionally, in the Description box, type a description for the trusted location.