سلام دوست عزیز
به آدرس زیر سر بزن حتما جوابتو می گیری
http://howprg.blogfa.com/post-11.aspx
rfg.jpg
به فرم FrmAdd برو و تابع Check رو نگاه کن
نمونه کد :
PrivateSub Check()
Try
If txtNumFact.Text = ""Or txtNameCustomer.Text = ""Then
MsgBox("شماره فاکتور و نام مشتری را وارد نمائید", MsgBoxStyle.ApplicationModal, "")
ExitSub
EndIf
If IsNumeric(txtNumFact.Text) = FalseThenExitSub
Dim i AsInteger
Dim con AsNew OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Application.Info.DirectoryPath & "\db.mdb")
Dim command AsNew OleDbCommand("Select * From Tbl_db Where NumFact=@NumFact", con)
command.Parameters.AddWithValue("@NumFact", txtNumFact.Text)
Dim dr As OleDbDataReader
con.Open()
dr = command.ExecuteReader
While dr.Read
i = dr("NumFact")
EndWhile
If i > 0 Then
MessageBox.Show("عدد وارد شده تکراری است" + vbCrLf + "عدد دیگری را امتحان کنید", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
con.Close()
dr.Close()
ExitSub
EndIf
con.Close()
dr.Close()
Call ADD()
Catch ex As Exception
MsgBox(ex.Message)
ExitSub
EndTry
EndSub
PrivateSub ADD()
Application.DoEvents()
Dim strDate AsString = mskDate.Text
If ChDate.Checked = TrueThen
strDate = MdlDate.DateShamsi
EndIf
Try
Dim c AsNew OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & My.Application.Info.DirectoryPath & "\db.mdb")
Dim D_add AsNew OleDbDataAdapter
Dim g AsString = cmbGroup.Text
Dim M AsString = cmbMonth.Text
Dim co AsNew OleDbCommand("INSERT INTO Tbl_db(NumFact,NameCustomer,City,Masoolpey,MasoolN asb,[Month],[Group],Adr,Mobile,Tell,[Date],other)Values(@NumFact,@NameCustomer,@City,@Masool pey,@MasoolNasb,@Month,@Group,@Adr,@Mobile,@Tell,@ Date,@other)", c)
co.Parameters.AddWithValue("NumFact", txtNumFact.Text)
co.Parameters.AddWithValue("NameCustomer", txtNameCustomer.Text)
co.Parameters.AddWithValue("City", txtCity.Text)
co.Parameters.AddWithValue("Masoolpey", txtMasoolPey.Text)
co.Parameters.AddWithValue("MasoolNasb", txtMasoolNasb.Text)
co.Parameters.AddWithValue("Month", cmbMonth.Text)
co.Parameters.AddWithValue("Group", cmbGroup.Text)
co.Parameters.AddWithValue("Adr", txtadr.Text)
co.Parameters.AddWithValue("Mobile", txtmobile.Text)
co.Parameters.AddWithValue("Tell", txtTell.Text)
co.Parameters.AddWithValue("Date", strDate)
co.Parameters.AddWithValue("other", txtOther.Text)
c.Open()
co.ExecuteNonQuery()
c.Close()
MessageBox.Show("اطلاعات با موفقیت در بانک اطلاعاتی ثبت شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MsgBox(ex.Message)
EndTry
txtNumFact.Text = ""
txtadr.Text = ""
txtCity.Text = ""
txtMasoolNasb.Text = ""
txtMasoolPey.Text = ""
txtmobile.Text = ""
txtNameCustomer.Text = ""
txtOther.Text = ""
txtTell.Text = ""
mskDate.Text = ""
cmbGroup.SelectedIndex = 0
cmbMonth.SelectedIndex = 0
txtNumFact.Focus()
EndSub