OleDbConnection con;
StringBuilder StrBul;
DataSet ds;
OleDbDataAdapter da;
OleDbCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
DataLoad();
}
public void DataLoad()
{
connection();
DataTable dt = new DataTable();
StrBul = new StringBuilder();
StrBul.AppendFormat("SELECT Country_Id,Country_Name FROM Country_Registration");
da = new OleDbDataAdapter(StrBul.ToString(), con);
ds=new DataSet ();
da.Fill(dt);
ddlcountry.DataSource = dt;
ddlcountry.DataTextField = "Country_Name";
ddlcountry.DataValueField = "Country_Id";
ddlcountry.DataBind();
}
public void connection()
{
string StrConnection = ConfigurationManager.ConnectionStrings["EGPApplication"].ConnectionString;
con = new OleDbConnection(StrConnection);
if (con.State == ConnectionState.Open)
con.Close();
else
con.Open();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
connection();
string a = ddlcountry.SelectedValue;
StrBul = new StringBuilder();
StrBul.AppendFormat("Select max(SERVICECHARGE_ID) from Servicecharge_Details");
da = new OleDbDataAdapter(StrBul.ToString(), con);
ds = new DataSet();
da.Fill(ds);
Int32 int32Id = 0;
if (ds.Tables[0].Rows[0].ItemArray[0].ToString() == "")
{
int32Id = 1;
}
else
{
int32Id = Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[0].ToString()) + 1;
}
StrBul = new StringBuilder();
StrBul.AppendFormat("Insert into Servicecharge_Details Values({0},'{1}',{2},{3},{4})", int32Id, txtbankname .Text, txtservicecharge .Text ,ddlcountry.SelectedValue ,1 );
cmd = new OleDbCommand(StrBul.ToString(), con);
cmd.ExecuteNonQuery();
ClientScript.RegisterClientScriptBlock(GetType(), "aa", "alert('Data inserted successfully')", true);
Clear();
}
Im using this code for get country_id in dropdownlist from database. but while im inserting that value to another table the country_id should be same in all insert statement.example
if i select india as country the id is 1
if i select USA that one also getting the same country_id 1...but actual value is 2.
how can i solve this pblm.
is any other solution for that?plz help me to correct that error
Thanks