|
-
May 5th, 2003, 03:40 PM
#1
insert a row problem
I use a web service to add a new record to the DB.
it works 
but not always 
The following code works for one table of mine and not for the second (all the feilds are simple text without no roles on ms-access DB).
Why?
PHP Code:
#region add - adding a new course model to the DB.
/// <summary>
/// This service is used to add a new model to the DB.
/// It returns its caller a bolleanic answer whether or not
/// the operation succeeded.
/// </summary>
[System.Web.Services.WebMethod(Description = "This service adds a new model to the data base.")]
public bool add(String code,String name,String hours,String totStud)
{
bool added; // a variable that indicated whether the new row was added
OleDbConnection conn = new OleDbConnection(root);
conn.Open();
String command = "select * from model";
OleDbDataAdapter adapter = new OleDbDataAdapter( command,conn);
DataSet ds = new DataSet();
OleDbCommandBuilder cm = new OleDbCommandBuilder(adapter);
adapter.Fill(ds);
DataRow newrow = ds.Tables[0].NewRow();
newrow["modelID"] = code;
newrow["name"] = name;
newrow["hours"] = hours;
newrow["maxNumStud"] = totStud;
ds.Tables[0].Rows.Add(newrow);
adapter.UpdateCommand = cm.GetUpdateCommand();
try
{
adapter.Update(ds.Tables[0]);// ( ds,"students");
added = true;
}
catch
{
added = false; // if the adapter fails to update the DB
}
conn.Close();
return(added);
} // add method
#endregion
-
May 6th, 2003, 07:53 AM
#2
I think I got it
I thing that having a field with the name "index" is responsible for the bug.
Without this field everything make more sense
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|