PDA

View Full Version : add new record



mes
جمعه 28 فروردین 1383, 13:57 عصر
سلام
عزیزان ما میخام یه رکورد به فایل بانک اطلاعاتیم اضافه کنم به این صورت
Imports System.Data
'Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents t2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents t3 As System.Web.UI.WebControls.TextBox
Protected WithEvents t4 As System.Web.UI.WebControls.TextBox
Protected WithEvents t5 As System.Web.UI.WebControls.TextBox
Protected WithEvents t6 As System.Web.UI.WebControls.TextBox
Protected WithEvents t1 As System.Web.UI.WebControls.TextBox

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
Dim ds As New DataSet()
Dim con As OleDbConnection
'Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Dim newrow As DataRow
Dim cb As OleDbCommandBuilder
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con = New OleDbConnection("provider=microsoft.jet.oledb.4.0;" & "data source=/inetpub/wwwroot/amalak/amlak.mdb")
con.Open()
'cmd = New OleDbCommand("select * from t2", con)
da = New OleDbDataAdapter("select * from t1", con)
da.Fill(ds, "t1")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
newrow = ds.Tables("t1").NewRow()
newrow("user") = Val(t1.Text)
newrow("pass") = Val(t2.Text)
newrow("fname") = Val(t3.Text)
newrow("lname") = Val(t4.Text)
newrow("ph") = Val(t5.Text)
newrow("h") = Val(t6.Text)
ds.Tables("t1").Rows.Add(newrow)
cb = New OleDbCommandBuilder(da)
da.InsertCommand = cb.GetInsertCommand
da.Update(ds, "t1")

con.Close()
End Sub
End Class

اا تو این قسمت اشکال میده


da.Update(ds, "t1")

یا علی

MFCGalaxy
جمعه 28 فروردین 1383, 20:42 عصر
چرا از INSETT INTO و اشیا Command استفاده نمیکنید ؟ آیا الزامی داشتین که از این روش استفاده کنید ؟؟

mes
جمعه 28 فروردین 1383, 22:07 عصر
با استفاده از اشیا درست کار میکنه اما این...
راستش اون رو دوست ندارم و یه جورایی باید از این استفاده کنم.

mes
شنبه 29 فروردین 1383, 20:36 عصر
عزیزان کسی نمیتونه به من کمک کنه؟

mes
دوشنبه 31 فروردین 1383, 00:28 صبح
عزیزان کسی اشکال این کد مارو نمیدونه؟ :| :flower:

mes
دوشنبه 07 اردیبهشت 1383, 12:40 عصر
بابا شمارو به هر کی دوس دارین کمک :(

mes
پنج شنبه 10 اردیبهشت 1383, 11:26 صبح
عزیزان اینو که جواب ندادین ! میشه بهم بگین چجوری میشه تو یه شیی کانکشن دیتا سورس رو با استفاده از پروپرتیش جایی روی سرورم قرار بدم ؟ یعنی فایل دیتا بیسم رو روی هاستم ÷یدا کنه ؟
با تشکر