values are not added into the gridview?

Posted by Sudheep.grandhe under C# on 11/8/2011 | Points: 10 | Views : 1094 | Status : [Member] | Replies : 11
Hi,

I've a problem in the newinvoice form.when ever iam trying to add the data it wont display in gridview.please do the needful.

Best,
Sudheep.



Responses

Posted by: Blessyjees on: 11/8/2011 [Member] Bronze | Points: 25

Up
0
Down
hi,

could you provide your code.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/8/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

I will posted my coding here.please find it.when ever i am entering the data.it won't add and displayed in the gridview?

private void btn_add_Click(object sender, EventArgs e)
{
string strondate, strondate1, ondate;
string strinvoicedate, strinvoicedate1, invoicedate2;
//SqlConnection con = new SqlConnection("data source=mars-104;intial catalog=marsweb.imageimpacts;integrated security=true");
DBConnection db = new DBConnection();

SqlConnection con = db.opencon();
SqlCommand cmd = new SqlCommand("insert into tbl_temp (invoiceno,particulars,quantity,perprice,amount,orderno,compname,invoicedate,ondate,invoiceid)values(@invoiceno,@particulars,@quantity,@perprice,@amount,@orderno,@compname,@invoicedate,@ondate,@invoiceid)", con);
cmd.Parameters.AddWithValue("@invoiceno", txt_invoiceno.Text);
cmd.Parameters.AddWithValue("@particulars", cmb_particulars.SelectedValue );
cmd.Parameters.AddWithValue("@quantity", txt_quantity.Text);
cmd.Parameters.AddWithValue("@perprice", txt_perprice.Text);
cmd.Parameters.AddWithValue("@amount", txt_amount.Text);
cmd.Parameters.AddWithValue("@orderno", txt_orderno.Text);
cmd.Parameters.AddWithValue("@compname", cmb_companyname.SelectedValue );

strinvoicedate = txt_invoicedate.Text;
if (strinvoicedate != "null")
{
char[] separator = new char[] { ' ' };
string[] s1 = strinvoicedate.Split(separator);
string date2 = s1[0].ToString();
Console .WriteLine (date2 );
if (date2 != "null")
{
char[] separator1 = new char[] { '/' };
string[] s2 = date2.Split(separator1);
string day = s2[0].ToString();
string month = s2[1].ToString();
string year = s2[2].ToString();
strinvoicedate1 = (month + "/" + day + "/" + year );
invoicedate2 = strinvoicedate1;
cmd.Parameters.AddWithValue("@invoicedate", invoicedate2);
}
}
strondate = txt_ondate.Text;
if (strondate !="null")
{
char [] separator=new char [] { ' ' };
string [] s1=strondate.Split (separator );
string date1=s1[0].ToString ();
if (date1 !="null")
{
char [] separator1=new char [] { '/' };
string [] s2= date1 .Split (separator1 );
string day=s2[0].ToString ();
string month=s2[1].ToString ();
string year=s2[2].ToString ();
strondate1 =(month + "/" + day + "/" +year );
ondate =strondate1 ;
cmd.Parameters .AddWithValue ("@ondate",ondate );
}
}
cmd.Parameters .AddWithValue ("@invoiceid",txt_invoiceno .Text );
SqlDataAdapter da=new SqlDataAdapter (cmd );
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.ExecuteNonQuery ();
con.Close ();
txt_quantity .Text ="";
txt_perprice .Text ="";
txt_amount .Text ="";
netamount ();
loadparticularsdata ();
vatamount ();
}

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 11/8/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

I could n't find any code to bind data to the grid view. This is a code for inserting data to the table, right?

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/8/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

for binding the data to gridview what code i have to write and where i have to write the code.can you please send the code.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 11/8/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

After insert function execute successfully. You can call a function to bind data to gridview.

Private void BindGrid()

{
SqlConnection con = new SqlConnection("data source=mars-104;intial catalog=marsweb.imageimpacts;integrated security=true");
con.Open();
string sql="select * from tbl_temp";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataAdapter da=new SqlDataAdapter(cmd);
Datasset ds=new DataSet();
da.Fill(ds);
if(ds.Tables[0].count>0 && ds.Tables[0].Rows.Count >0)
{
gridView.DataSource=ds;
gridView.Bind();
}

}

I am not tried to compile this code in vs. so correct if you are getting any syntax errors.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/8/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

it wont add the details to the gridview


Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 11/8/2011 [Member] Bronze | Points: 25

Up
0
Down
hi,

do you have data in the table. CAn you debug the code and check. are you getting any error.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/8/2011 [Member] Starter | Points: 25

Up
0
Down
HI,

i am having the data in the table.if i debug the code it wont execute the if part it jumps out of the if part.datagridview .bind; property it wont shows
if(ds.Tables[0].count>0 && ds.Tables[0].Rows.Count >0)
{ gridView.DataSource=ds;//it wont execute this part.

gridView.Bind();

}

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RohiK on: 11/8/2011 [Member] Starter | Points: 25

Up
0
Down
how you add gridview on page ?
give your aspx page code.

Happy Programming!!
Rohi

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/8/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

currently iam using windows applications.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 11/9/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

In the table data was not there.what can i do now.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response