PDA

View Full Version : سوال: مشکل در اتصال به پایگاه داده ی اکسس



moh.mon
شنبه 08 خرداد 1389, 21:41 عصر
سلام دوستان.
من کد زیر رو برای اتصال به پایگاه داده ی اکسس نوشتم ولی میگه که name متعلق به هیچ جدولی نیست.
کمک کنید. من که حسابی گیج شدم http://www.forum.p30world.com/images/New-smile/N_aggressive%20%2840%29.gif

OleDbConnection oled= new OleDbConnection();
oled.ConnectionString= @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Mohammad\Documents\Visual Studio 2008\Projects\WebSite3\hamayesh.accdb";
oled.Open();

OleDbDataAdapter oled_dataadaptr= new OleDbDataAdapter();
oled_dataadaptr = new OleDbDataAdapter("SELECT Name, Surname, [E-mail], [Phone-number], Company, [Company-Adress], Website, egamat FROM [personal_info]", oled);

OleDbCommandBuilder oled_comandbuilder= new OleDbCommandBuilder();
DataTable oled_datatable = new DataTable();
int oled_rowposition =0;

DataRow oled_datarow = oled_datatable.NewRow();
oled_datarow["Name"] = TextBoxName.Text;
oled_datarow["Surname"] = TextBoxSurename.Text;
oled_datarow["[E-mail]"] = TextBoxemail.Text;
oled_datarow["[Phone-number]"] = TextBoxphone.Text;
oled_datarow["Company"] = TextBoxcompany.Text;
oled_datarow["[Company-Adress]"] = TextBoxcompanyadress.Text;
oled_datarow["Website"] = TextBoxAdress.Text;
oled_datarow["egamat"] = TextBoxegamat.Text;

oled_datatable.Rows.Add(oled_datarow);
oled_dataadaptr.Update(oled_datatable);
oled_rowposition = oled_datatable.Rows.Count -1;

General-Xenon
شنبه 08 خرداد 1389, 23:47 عصر
سلام دوستان.
من کد زیر رو برای اتصال به پایگاه داده ی اکسس نوشتم ولی میگه که name متعلق به هیچ جدولی نیست.
کمک کنید. من که حسابی گیج شدم http://www.forum.p30world.com/images/New-smile/N_aggressive%20%2840%29.gif

OleDbConnection oled= new OleDbConnection();
oled.ConnectionString= @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Mohammad\Documents\Visual Studio 2008\Projects\WebSite3\hamayesh.accdb";
oled.Open();

OleDbDataAdapter oled_dataadaptr= new OleDbDataAdapter();
oled_dataadaptr = new OleDbDataAdapter("SELECT Name, Surname, [E-mail], [Phone-number], Company, [Company-Adress], Website, egamat FROM [personal_info]", oled);

OleDbCommandBuilder oled_comandbuilder= new OleDbCommandBuilder();
DataTable oled_datatable = new DataTable();
int oled_rowposition =0;

DataRow oled_datarow = oled_datatable.NewRow();
oled_datarow["Name"] = TextBoxName.Text;
oled_datarow["Surname"] = TextBoxSurename.Text;
oled_datarow["[E-mail]"] = TextBoxemail.Text;
oled_datarow["[Phone-number]"] = TextBoxphone.Text;
oled_datarow["Company"] = TextBoxcompany.Text;
oled_datarow["[Company-Adress]"] = TextBoxcompanyadress.Text;
oled_datarow["Website"] = TextBoxAdress.Text;
oled_datarow["egamat"] = TextBoxegamat.Text;

oled_datatable.Rows.Add(oled_datarow);
oled_dataadaptr.Update(oled_datatable);
oled_rowposition = oled_datatable.Rows.Count -1;
سلام دوست عزیز.
فکر کنم اگر



SELECT * FROM [TB_NAME]



oled_datarow[0] = TextBoxegamat.Text;

این طوری بنویسی درست بشه

moh.mon
یک شنبه 09 خرداد 1389, 09:28 صبح
سلام دوست عزیز. کاری که گفتین رو انجام دادم. ولی باز همون مشکل وجود داره. با این دستور مشکل داره:

oled_dataadaptr.Update(oled_datatable);
این هم خطا یی که میده:

System.InvalidOperationException was unhandled by user code
Message="Update requires a valid InsertCommand when passed DataRow collection with new rows."
Source="System.Data"
StackTrace:
at System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at _Default.Button1_Click(Object sender, EventArgs e) in c:\Users\Mohammad\Documents\Visual Studio 2008\WebSites\WebSite3\Default.aspx.cs:line 46
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: