Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace ASSIGNMENT_WORK.Forms
{
    public partial class addnumber : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnResult_Click(object sender, EventArgs e)
        {
            int firstNumber, secondNumber, result;
            firstNumber = Convert.ToInt32(txtFirstno.Text.Trim());
            secondNumber = Convert.ToInt32(txtSecondno.Text.Trim());
            result = firstNumber + secondNumber;
            txtresult.Text = Convert.ToString(result);
            SqlConnection cnn=new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
        cnn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "select * from  Add";
        cmd.Connection = cnn;
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds, " Add ");
        SqlCommandBuilder cb = new SqlCommandBuilder(da);
        DataRow drow = ds.Tables["Add"].NewRow();
        drow["result"] = txtresult.Text;
        ds.Tables["Add "].Rows.Add(drow);
        da.Update(ds, " Add ");
        string script = @"<script language=""javascript"">
        alert('Information have been Saved Successfully.......!!!!!.');
       </script>;";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "myJScript1", script);

        }
    }
}
Posted
Updated 13-Sep-13 3:02am
v2
Comments
Salman622 13-Sep-13 9:04am    
what is Error in your code please specify

use select command text as like below

cmd.CommandText = "select * from [Add]";
 
Share this answer
 
Comments
Member 10184990 13-Sep-13 9:18am    
thanks sir (CB Sharma)
Remove spaced before and after "Add" like this.

ds.Tables["Add"].Rows.Add(drow);
da.Fill(ds, "Add");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900