Fetch value from SQL DataSource and use select command to fetch individual row details.
DataView dv = (DataView)SqlDataSource.Select(DataSourceSelectArguments.Empty);
int reorderedProducts = (int)dv.Table.Rows[0][2];
DataRow[] dr = dv.Table.Select("Code='" + val + "'");
string id = dr[0]["Id"].ToString();
Code to fetch Data from database using SQL DataAdaptor and fill DataSet
if (con.State == ConnectionState.Closed)
{
con.Open(); // check connection and if closed then open it.
}
SqlCommand cmd = new SqlCommand();
cmd.Connection = con; //Connection object
cmd.CommandText = "Stored Procedure Name";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Id", SqlDbType.NVarChar).Value = Convert.ToInt32(id); //Parameter
SqlDataAdapter adt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adt.Fill(ds);
Code to save data into database
if (con.State == ConnectionState.Closed)
{
con.Open(); // check connection and if closed then open it.
}
SqlCommand cmd = new SqlCommand(); // Declare Sqlcommand Function
cmd.Connection = con;
cmd.CommandText = "Stored Procedure Name";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@id", SqlDbType.NVarChar).Value = txtbox.Text;
cmd.Parameters.Add("@ErrorStatus", SqlDbType.Int).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
if (Convert.ToInt32(cmd.Parameters["@ErrorStatus"].Value) == 1)
{
reset();
DisplayAJAXMessage(this, "Inserted Successfully");
}
To display message in popup
static public void DisplayAJAXMessage(Control page, string msg)
{
string myScript = String.Format("alert('{0}');", msg);
ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);
}
DataView dv = (DataView)SqlDataSource.Select(DataSourceSelectArguments.Empty);
int reorderedProducts = (int)dv.Table.Rows[0][2];
DataRow[] dr = dv.Table.Select("Code='" + val + "'");
string id = dr[0]["Id"].ToString();
Code to fetch Data from database using SQL DataAdaptor and fill DataSet
if (con.State == ConnectionState.Closed)
{
con.Open(); // check connection and if closed then open it.
}
SqlCommand cmd = new SqlCommand();
cmd.Connection = con; //Connection object
cmd.CommandText = "Stored Procedure Name";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Id", SqlDbType.NVarChar).Value = Convert.ToInt32(id); //Parameter
SqlDataAdapter adt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adt.Fill(ds);
Code to save data into database
if (con.State == ConnectionState.Closed)
{
con.Open(); // check connection and if closed then open it.
}
SqlCommand cmd = new SqlCommand(); // Declare Sqlcommand Function
cmd.Connection = con;
cmd.CommandText = "Stored Procedure Name";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@id", SqlDbType.NVarChar).Value = txtbox.Text;
cmd.Parameters.Add("@ErrorStatus", SqlDbType.Int).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
if (Convert.ToInt32(cmd.Parameters["@ErrorStatus"].Value) == 1)
{
reset();
DisplayAJAXMessage(this, "Inserted Successfully");
}
To display message in popup
static public void DisplayAJAXMessage(Control page, string msg)
{
string myScript = String.Format("alert('{0}');", msg);
ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true);
}
No comments:
Post a Comment