But in my code i have the method.I tried this also with vb, there it works except the update method :/. But not with c# :(((I don't know what to do :((
using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Data;namespace WebApplication3{ public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bingridview(); } } protected void Button1_Click(object sender, EventArgs e) { bingridview(); } public void bingridview() { sql = "select id,name, adress from user" string connstr = "Data Source=*****;Initial Catalog=pwdb;Integrated Security=True"; SqlConnection conn = new SqlConnection(connstr); SqlDataAdapter sqladapter; SqlConnection connection; DataSet myds = new DataSet(); DataSet changes = new DataSet(); SqlCommand cmd = new SqlCommand(sql, conn); connection = new SqlConnection(connstr); //Dim datareader As SqlDataReader connection.Open(); sqladapter = new SqlDataAdapter(sql, connection); //sqladapter.SelectCommand = cmd sqladapter.Fill(myds); connection.Close(); GridView1.DataSource = myds; DataBind(); }
using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Data;namespace WebApplication3{ public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { bingridview(); } } protected void Button1_Click(object sender, EventArgs e) { bingridview(); } public void bingridview() { sql = "select id,name, adress from user" string connstr = "Data Source=*****;Initial Catalog=pwdb;Integrated Security=True";
SqlConnection conn = new SqlConnection(connstr); SqlDataAdapter sqladapter; SqlConnection connection; DataSet myds = new DataSet(); DataSet changes = new DataSet(); SqlCommand cmd = new SqlCommand(sql, conn); connection = new SqlConnection(connstr); //Dim datareader As SqlDataReader connection.Open(); sqladapter = new SqlDataAdapter(sql, connection); //sqladapter.SelectCommand = cmd sqladapter.Fill(myds); connection.Close(); GridView1.DataSource = myds; DataBind(); }
namespace WebApplication3 { public partial class _Default { /// <summary> /// form1 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.HtmlControls.HtmlForm form1; /// <summary> /// Typ control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.TextBox ID; /// <summary> /// Mandant control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.TextBox name; /// <summary> /// SID control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.TextBox adress; /// <summary> /// Button1 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button Button1; /// <summary> /// Button2 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button Button2; /// <summary> /// GridView1 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.GridView GridView1; }}
Attachment: WebApplication4.rar