سلام و خسته نباشید به همه دوستان
با وجود اموزش های زیادی که توی انجمن موجود هست ، خیلی از دوستان هنوز مشکل دارن با دیتابیس
این سورس زیر، از طریق کتابخونه sql با دیتابیس کار میکنه و 4 عمل سلکت، اپدیت، اینسرت و دیلت رو باهاش انجام میدیم...
سعی کردم خیلی خیلی ساده و روون کد بزنم که دوستانی که مشکل دارن راحت متوجه بشن...
غیر از دیتابیس دو سه تا چیز دیگه هم تو سورس هست:
دیزاینر اسکریپت کاملا انجام شده.
مسیج باس 2 رو استفاده کردیم و قبل از هر کاری از کاربر میپرسیم مطمئن هست یا نه
و چک میکنیم که فیلد ها خالی هستن یا نه که در صورت خالی بودن، چیزی ثبت نمیشه و کاربر اخطار دریافت میکنه
موفق تر باشید
دانلود سورس و دیتابیس....
www.answercenter.ir
تصاویر محیط نرم افزار
main activity
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim sql As SQL
Dim cur As Cursor
Dim meghdar As String
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Button1 As Button
Private EditText1 As EditText
Private EditText2 As EditText
Private ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
'avval bayad database ro copy konim va bad initialize sh konim'
If File.Exists(File.DirInternal,"db.db") = False Then
File.Copy(File.DirAssets,"db.db",File.DirInternal,"db.db")
End If
If sql.IsInitialized = False Then
sql.Initialize(File.DirInternal,"db.db",True)
End If
'bayad ettelaate data base ro bekhoonam o berizam tooye list view'
cur = sql.ExecQuery("SELECT * FROM mytbl")
For i = 0 To cur.RowCount - 1
cur.Position = i
ListView1.AddSingleLine2(cur.GetString("title"),cur.GetInt("id"))
Next
'ye shart mizaram ke age chizi too list view nabood masalan be karbar begiim '
'ke ettelaate jadid ra vared konid o in harfa...'
If ListView1.Size = 0 Then
Msgbox("ettelaati mojood nist"&CRLF&"az paiin safhe vared konid","answercenter.ir-->shahab.es")
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)'''''''''''''in ghesmat , id ro mifreste be 1 activity dg'''''''
meghdar = Value
StartActivity(content)
End Sub
Sub ListView1_ItemLongClick (Position As Int, Value As Object)'''''''in ghesmat baray hazfe ettelaat az data base hastesh''''
'dar in ghesmat hazf ettelaato anjam midim'
Dim a As Int
a = Msgbox2("motmaennid???","answercenter.ir-->shahab.es","bale","","na",Null)
If a = DialogResponse.POSITIVE Then
'injaa vaarede data base mikonim'
sql.ExecNonQuery("DELETE FROM mytbl WHERE id = '"& Value &"'")
ToastMessageShow("hazf shod",False)
'dobare list view ro load mikonam ta taghirat maloom beshe'
ListView1.Clear
cur = sql.ExecQuery("SELECT * FROM mytbl")
For i = 0 To cur.RowCount - 1
cur.Position = i
ListView1.AddSingleLine2(cur.GetString("title"),cur.GetInt("id"))
Next
End If
End Sub
Sub Button1_Click'''''''insert dar database'''''''
'dar inja ettelaate jadid ro vaarede database mikonimmm'
'avval check mikonam ke edittext haa khali nabashan'
'bad az karbar miporsam ke motmaeennnid???'
If EditText1.Text = "" Or EditText2.Text = "" Then
ToastMessageShow("matni vaared nashode ast",False)
Else
Dim a As Int
a = Msgbox2("motmaennid???","answercenter.ir-->shahab.es","bale","","na",Null)
If a = DialogResponse.POSITIVE Then
'injaa vaarede data base mikonim'
sql.ExecNonQuery("INSERT INTO mytbl (id,title,content) VALUES (null,'"& EditText1.Text &"','"& EditText2.text &"')")
ToastMessageShow("sabt shod",False)
'dobare list view ro load mikonam ta taghirat maloom beshe'
ListView1.Clear
cur = sql.ExecQuery("SELECT * FROM mytbl")
For i = 0 To cur.RowCount - 1
cur.Position = i
ListView1.AddSingleLine2(cur.GetString("title"),cur.GetInt("id"))
Next
End If
End If
End Sub
content activity
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Button1 As Button
Private EditText1 As EditText
Dim id As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("content")
id = Main.meghdar
'meghdar be edit text baraye viraayeh'
Main.cur = Main.sql.ExecQuery("SELECT * FROM mytbl WHERE id = " & id)
Main.cur.Position = 0
EditText1.Text = Main.cur.GetString("content")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click''''emaal taghirat va viraayesh''''
Dim a As Int
a = Msgbox2("motmaennid???","answercenter.ir-->shahab.es","bale","","na",Null)
If a = DialogResponse.POSITIVE Then
'injaa vaarede data base mikonim'
Main.sql.ExecNonQuery("UPDATE mytbl SET content = '"& EditText1.Text &"' WHERE id = '"& id &"'")
ToastMessageShow("sabt shod",False)
'dobare edittetx ro load mikonam ta taghirat maloom beshe'
EditText1.Text = ""
Main.cur = Main.sql.ExecQuery("SELECT * FROM mytbl WHERE id = " & id)
Main.cur.Position = 0
EditText1.Text = Main.cur.GetString("content")
End If
End Sub