אני מנסה כמו מסכן לעשות INSERT בASP.NET דרך WEB SERVICE.רושם לי
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at Service.Insertm(Users user) --- End of inner exception stack trace ---
|
ואני לא ממש חושב שיש |=.. הדפסתי את זה על המסך כדי לראות שהמשפט באמת כמו שאני רוצה וזה הדפיס את זה:
INSERT INTO Users (user_id,user_name,password,email,user_group,city,phone,avatar) VALUES(@idparam,@nameparam,@passwordparam,@emailparam,@groupparam,@cityparam,@picparam)
|
בדקתי גם את המיקום של הDB.. הוא בסדר גמור.
הדף בCLIENT: (פעולת כפתור)
protected void Button1_Click(object sender, EventArgs e) { localhost.Users newuser = new localhost.Users(); localhost.Service ms = new localhost.Service(); newuser.ID = ms.GetLastUserID(); newuser.Name=nametxt.Text; newuser.Password=passwordtxt.Text; newuser.Email = emailtxt.Text; newuser.Avatar = avtartxt.Text; newuser.Phone = phonetxt.Text; newuser.Group = 1; newuser.City = citytxt.Text; ms.Insertm(newuser); ActionLabel.Text = "נרשמת בהצלחה"; }
|
הWEB SERVICE:
using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Data; using System.Data.OleDb;
public class Service : System.Web.Services.WebService { public Service () {
//Uncomment the following line if using designed components //InitializeComponent(); } public DataSet Insertm(Users user) { string st; DataSet ds = new DataSet(); int x; st = @"provider=Microsoft.jet.oledb.4.0;Data Source = " + Server.MapPath("~/Data/db6.mdb"); OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = st; OleDbCommand cmmd = new OleDbCommand("INSERT INTO Users (user_id,user_name,password,email,user_group,city,phone,avatar) VALUES(@idparam,@nameparam,@passwordparam,@emailparam,@groupparam,@cityparam,@picparam)", conn); cmmd.Parameters.Add("@idparam", OleDbType.Numeric).Value = (int)user.ID; cmmd.Parameters.Add("@nameparam", OleDbType.VarChar).Value = user.Name.ToString(); cmmd.Parameters.Add("@emailparam", OleDbType.VarChar).Value = user.Email.ToString(); cmmd.Parameters.Add("@passwordparam", OleDbType.VarChar).Value = user.Password.ToString(); cmmd.Parameters.Add("@groupparam", OleDbType.Numeric).Value = (int)user.Group; cmmd.Parameters.Add("@cityparam", OleDbType.VarChar).Value = user.City.ToString(); cmmd.Parameters.Add("@picparam", OleDbType.VarChar).Value = user.Avatar.ToString(); conn.Open(); x = cmmd.ExecuteNonQuery(); if (x != 0) { string my_quary2 = "Select * Users"; OleDbCommand cmmd2 = new OleDbCommand(my_quary2, conn); OleDbDataAdapter da = new OleDbDataAdapter(cmmd2); da.Fill(ds); } conn.Close(); return (ds); //return cmmd.CommandText.ToString(); } public int GetLastUserID() { DataSet ds = new DataSet(); string st = @"provider=Microsoft.jet.oledb.4.0;Data Source = " + Server.MapPath("~/Data/db6.mdb"); OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = st; conn.Open(); string my_quary2 = "Select * From Users"; OleDbCommand cmmd2 = new OleDbCommand(my_quary2, conn); OleDbDataAdapter da = new OleDbDataAdapter(cmmd2); da.Fill(ds); conn.Close(); if (ds.Tables.Rows.Count != 0) { return int.Parse(ds.Tables.Rows.Rows.Count - 1].ToString()) + 1; } else { return 0; } } }
|
חבר'ה אני ממש צריך את העזרה שלכם :(.
תודה
.

