How to update server data through a webservice by using ADO.NET and Visual C#.NET
WebMethod
public void UpdateDeMo1(DataSet ds)
{
LayerAccess ac = new LayerAccess();
string[] parameters = { };
object[] values = { };
SqlDataAdapter da = new SqlDataAdapter();
da = ac.getDataAdapter("P_Demo", parameters, values);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(ds.Tables[0]);
//return ds;
}
But the error occurs when calling WebMethod.
private void simpleButton1_Click(object sender, EventArgs e)
{
//ud.AutoUpdateDemo(gridControl1);
DataTable dt = new DataTable();
DataTable dtt = new DataTable();
dt = (DataTable)gridControl1.DataSource;
dtt = dt.Copy();
DataSet ds = new DataSet("B");
ds.Tables.Add(dtt);
DataSet dschang = new DataSet();
dschang = ds.Copy();
sv.UpdateDeMo1(dschang.Copy());
}
Please help me.
Related
This is my code, but when I run it, I get no results:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDataList();
DataSet ds = GetData();
r1.DataSource = ds;
r1.DataBind();
}
}
Code to populate the repeater starts here:HERE
private DataSet GetData()
{
//GET VALUE FROM URL
this.Target = Request.QueryString["Loctn"];
Citytxt.Text = Target;
String cs = "Data Source=KISAKA;Initial Catalog=ACCOMMODATION;Integrated Security=True;";
using (SqlConnection con = new SqlConnection(cs))
{
SqlDataAdapter da = new SqlDataAdapter("Select * from ACC_Facility where Location_City = '"+ Target +"'", con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
I do not get any error messages, but the Datagrid won't show any Data from my Database.
var con = new MySqlConnection("server= localhost; database=fußballmanager; Uid=root;Pwd=;");
private void Form4_Load(object sender, EventArgs e)
{
MySqlDataAdapter da = new MySqlDataAdapter("Select * from tbl_anmeldedaten", con);
da.SelectCommand.CommandType = CommandType.Text;
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
I got this error "dynamic sql generation is not supported against multiple base tables" in my project.
i got the error on "da.update(dt)" line.
this is the code which i got the error...`so help me how can i solve it..
OleDbDataAdapter da;
DataSet ds = null;
BindingSource bsource = new BindingSource();
OleDbCommand cmd;
public void BindData()
{
cmd = new OleDbCommand("select t.srno,c.AccNumber2,c.Name,t.Admission_Fee,t.Family_fund,t.MonthlyCollection,t.MonthlyDeposit from transDemand t inner join Customer c on t.AccNumber=c.AccNumber where t.IssueDate=#IssueDate and c.Dismember=false", con);
cmd.Parameters.Add("#IssueDate", OleDbType.Date).Value = datesearch.Value.ToString("dd-MM-yyyy");
da = new OleDbDataAdapter(cmd);
ds = new DataSet();
//dt = new DataTable();
//da.Fill(dt);
OleDbCommandBuilder cmdbuild = new OleDbCommandBuilder(da);
da.Fill(ds, "A");
bsource.DataSource = ds.Tables["A"];
dataGridView1.DataSource = bsource;
}
private void btnupdate_Click(object sender, EventArgs e)
{
DataTable dt = ds.Tables["A"];
this.dataGridView1.BindingContext[dt].EndCurrentEdit();
da.Update(dt);
BindData();
}
Now I'm trying to solve this problem. But I don't know why it didn't work.
I've finished to change data in datagridview form, but the sqlite file in desktop wasn't changed.
namespace Ex1
{
public partial class Form1 : Form
{
int initValue = 0;
String chkString;
SQLiteConnection conn = new SQLiteConnection("Data Source=I:\\Coding\\VS\\Study1\\Ex1\\Ex1\\Test.db;Version=3;");
SQLiteDataAdapter adapter = null;
BindingSource bsOrigin = null;
DataSet ds = null;
Random rand = new Random();
KnownColor[] Colors = (KnownColor[])Enum.GetValues(typeof(KnownColor));
KnownColor randColor;
public Form1()
{
InitializeComponent();
textBox1.Text = initValue.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
bsOrigin = new BindingSource();
ds = GetData();
bsOrigin.DataSource = ds.Tables[0];
dataGridView1.DataSource = bsOrigin;
}
private DataSet GetData()
{
adapter = new SQLiteDataAdapter("SELECT * from Skill", conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds;
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
adapter = new SQLiteDataAdapter("SELECT * from Skill", conn);
BindingSource bs = (BindingSource)dataGridView1.DataSource;
DataTable dt = bs.DataSource as DataTable;
adapter.Update(dt);
}
}
}
Is there anyone who can teach me?
I use this method:
public void saveData ()
{
SQLiteDataConnection con = new SQLiteDataConnection("yourconnectionstring");
SQLiteDataAdapter da= new SQLiteDataAdapter("Select statement", con);
SQLiteCommandBuiler com=new SQLiteCommandBuiler(da);
DataSet ds= new DataSet ();
DataTable dt = new DataTable ():
DataRow dr;
con.Open();
da.fill(ds, "tablename");
cn.Close();
dt=ds.Tables["tablename"];
dr=dt.NewRow();
dr["rowname"]=value;
//"same for the other rows"
dr.Rows.Add(dr);
da.Update(dt.Select(null, null, DataViewRowState.Added));
}
you should also check the file permission, I have seen issues with sqlite when they are access from certain folders, the desktop was one.
I tried to save a record from a query into a DataRow, but did not make it. I could need some help. This my code:
private DataSet CreateDataSet()
{
DataSet ds = new DataSet();
// create Countries table and columns
DataTable dtApplications = ds.Tables.Add("Applications");
DataColumn dtApplicationID = dtApplications.Columns.Add("ApplicationID", typeof(int));
DataColumn dtApplicationName= dtApplications.Columns.Add("ApplicationName", typeof(string));
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(MoahannedConnectionString);
SqlCommand cmd1 = new SqlCommand("select AppID,AppName from Application", con);
SqlDataAdapter da = new SqlDataAdapter();
SqlDataReader sdr = null;
dt.TableName = "Application";
con.Open();
sdr = cmd1.ExecuteReader();
while (sdr.Read())
{
AddDataToTable(dtApplicationID, dtApplicationName, dtApplications, ds);
}
}
private void AddDataToTable(DataColumn ID, DataColumn Name, DataTable myTable,DataSet ds)
{
DataRow row;
row = myTable.NewRow();
row["ApplicationID"] = ID;
row["ApplicationName"] = Name;
myTable.Rows.Add(row);
}
You can use the DataAdapter directly to load a DataTable:
using(var da = new SqlDataAdapter("select AppID,AppName from Application", con))
{
da.Fill(dt);
}
The rest of the code above is redundant in my opinion.
Side-note: You're getting the exception because you want to pass a field of a record to a DataRow's field. But actually you're passing the DataColumn.
This would work but is unnecessary:
row["ApplicationID"] = sdr.GetInt32(sdr.GetOrdinal("ApplicationID"));
row["ApplicationName"] = sdr.GetString(sdr.GetOrdinal("ApplicationName"));
Where sdr is your DataReader.