עריכת טבלת מ DB

udiko

New member
עריכת טבלת מ DB

אני מנסה לבנות טבלה שנשלפת מ DB וניתנת לעריכה גררתי את הטבלה, DATASET ו DATAGRID לדף הוספתי עמודת edit,updata,cancel ואת 2 הפונקציות
private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { oleDbDataAdapter1.Fill( dataSet1); DataGrid1.DataSource = dataSet1; DataGrid1.DataBind(); } } private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { DataGrid1.EditItemIndex = e.Item.ItemIndex; DataGrid1.DataBind(); }​
חסר לי משהו כדי ש EDIT יעבוד, אני לא יודע מה
 

udiko

New member
נסיון לעדכון מודיע על שגיאה

בשורה 156
Line 154: TextBox txtCategoryName = (TextBox)e.Item.Cells[2].Controls[0]; Line 155: Line 156: oleDbCommand1.Parameters["@CategoryName"].Value = txtCategoryName.Text; Line 157: oleDbCommand1.Parameters["@CategoryID"].Value = DataGrid1.DataKeys[e.Item.ItemIndex]; Line 158:​
השגיאה An OleDbParameter with ParameterName '@CategoryName' is not contained by this OleDbParameterCollection. השאילתה היא זו:
UPDATE GalleryCategory SET CategoryName = @ CategoryName WHERE (CategoryID = @ CategoryID)​
אני מנסה את זה על ACCESS, אולי השאילתה לא נכונה ?
 

gilad g

New member
הבעיה היא לא השאילתה..

הבעיה היא שאלה הוספת את הפרמטר לקולקשן של הפרמטרים --
oleDbCommand1.Parameters.Add("@CategoryName", OleDbType.VarChar).Value = txtCategoryName.Text; oleDbCommand1.Parameters.Add("@CategoryID", OleDbType.VarChar).Value = DataGrid1.DataKeys[e.Item.ItemIndex];​
עכשיו זה אמור לעבוד
 

gilad g

New member
אמממ

ואם CategoryID הוא מסוג מספר, אז:
oleDbCommand1.Parameters.Add("@CategoryID", OleDbType.Integer).Value = DataGrid1.DataKeys[e.Item.ItemIndex];​
(יכול להיות ש-Numeric יעבוד, במקום - לא בדקתי...)
 

udiko

New member
עכשיו אני מקבל שגיאה

The type or namespace name 'OleDbType' could not be found (are you missing a using directive or an assembly reference?)
 

udiko

New member
החלפתי אותו ב SqlDbType והבעיה נפתר

אבל עכשיו אני בכלל מבולבל איך SQLDB קשור בכלל, הרי דובר על ACCESS עם OLEDB
 

gilad g

New member
שכחת לעשות את ה-using הנכון?

using System.Data.OleDb;​
יכול להיות שעשית את ה-using של SqlClient, במקום OleDb
 

udiko

New member
המשך

אני מצטער שאני מציק אבל לא מצאתי פתרון לשגיאה בגוגל זה השגיאה שאני מקבל עם לחיצה על UPDATE Syntax error (missing operator) in query expression '@ CategoryName'. זה השורה Line 148: oleDbCommand1.ExecuteNonQuery(); וזה הפונקציה
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { TextBox txtCategoryName = (TextBox)e.Item.Cells[2].Controls[0]; oleDbCommand1.Parameters.Add("@CategoryName", OleDbType.VarChar).Value = txtCategoryName.Text; oleDbCommand1.Parameters.Add("@CategoryID", OleDbType.Integer).Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex]; oleDbConnection1.Open(); oleDbCommand1.ExecuteNonQuery(); DataGrid1.EditItemIndex = -1; BindGrid(); oleDbConnection1.Close(); }​
תודה לך
 

udiko

New member
הוא מוסיף את זה אוטומטית

ושאני מנסה לשנות הוא נותן שגיאה
 

adam222

New member
DataGrid ואיחוד \ פיצול עמודות

אהלן, יש לי DG עם X עמודות כאשר 3 עמודות יש להן כותרת נוספת משותפת כלומר איחוד בין 3 שדות לשדה אחד וכשהוא מעל 3 העמודות הרצויות. ב-HTML זה היה נראה כמו ColSpan=3... יש למישהו רעיון? או אולי עדיף להשתמש באובייקט אחר מאשר DG כמו Reapeter ו-DL תודה רבה
 

udiko

New member
עכשיו הכל עובד חוץ מעברית

אני מעדכן את הטבלה ב ACCESS בהצלחה אבל שאני מכניס תווים בעברית הוא מתעלם מהם CHARSET ו CODEPAGE הם 1255 הבנתי שהנתונים נקלטים אוטומטית ביוניקוד אז לא אמור להיות בעיה הקוד:
public void MyDataGrid_Update(Object sender, DataGridCommandEventArgs e) { TextBox txtCategoryName = (TextBox)e.Item.Cells[2].Controls[0]; OleDbCommand myCommand = new OleDbCommand("update GalleryCategory set CategoryName=@CategoryName" + " where CategoryID=@CategoryID", myConnection); myCommand.Parameters.Add(new OleDbParameter("@CategoryName",OleDbType.VarChar,50)); myCommand.Parameters["@CategoryName"].Value = txtCategoryName.Text; myCommand.Parameters.Add(new OleDbParameter("@CategoryID",OleDbType.Integer)); myCommand.Parameters["@CategoryID"].Value = MyDataGrid.DataKeys[ (int)e.Item.ItemIndex]; myCommand.Connection.Open(); try { myCommand.ExecuteNonQuery(); MyDataGrid.EditItemIndex = -1; } catch { Label1.Text = "shit"; } myCommand.Connection.Close(); BindGrid(); }​
החלפת VarChar ב VarWChar לא פתרה את הבעיה
 
למעלה