Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have the following code in web.config file

HTML
<connectionstrings>
   <add name="ConnectionStringdb" connectionstring="Data Source=local; Initial Catalog=TeltonikaCRM; Persist Security Info=True; User ID=sa;password=Ali998877;">
     providerName="System.Data.SqlClient" />
   <add name="TeltonikaCRMConnectionString" connectionstring="Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Administrator\Documents\TeltonikaCRM.mdf;Integrated Security=True;Connect Timeout=30">
     providerName="System.Data.SqlClient" />
 </add></add></connectionstrings>


and the following in default.aspx.cs

C#
using System.Data.OleDb;
using System.ComponentModel;
using System.Drawing;
using System.Text;


namespace CRMTracking.Pages
{
    public partial class Default2 : System.Web.UI.Page
    {
        CRMTracking.Classes.DBConnect DBC;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                //Establishing the MySQL Connection
                DBC = new Classes.DBConnect(this.Page);
                DBC.SetSqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringdb"].ToString());
                DataTable dt = new DataTable();
                string query;
                SqlCommand SqlCommand;
                SqlDataReader reader;
                SqlDataAdapter adapter = new SqlDataAdapter();
                //Open the connection to db
                

                //Generating the query to fetch the contact details
                query = "SELECT * FROM UserInfo";

                SqlCommand = new SqlCommand(query, DBC.GetSqlConnection());

                //execute the query
                
                reader = SqlCommand.ExecuteReader();
                
                txtFName.Text = reader["UFName"].ToString();
                //Assign the results 
                GridView1.DataSource = reader;

                //Bind the data
                GridView1.DataBind();
            }     
        }
}
}


and a connection Class coding is

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI;

namespace CRMTracking.Classes
{
    
    public class DBConnect
    {
        Page Pg=new Page();
        SqlConnection SqlConn;

        public DBConnect(Page CurerntPg) {Pg = CurerntPg;}

        public void MsgBox(String Message)
        { Pg.ClientScript.RegisterStartupScript(Pg.GetType(), "MessageBox", "<script language='javascript'>alert('" + Message + "');</script>"); }

        public SqlConnection GetSqlConnection() {return SqlConn;}

        public void SetSqlConnection(String CString) 
        {
            try
            {
                SqlConn = new SqlConnection(CString);
                SqlConn.Open();
            }
            catch (Exception ce)
            { MsgBox("Error Opening Connection to Sql Server....." + ce); return; }      
            //
        }
}
}



but the result is just a blank page please help me
Posted
Updated 27-Jul-15 21:41pm
v2
Comments
Aravindba 28-Jul-15 3:42am    
unnecessary don't use bold......

1 solution

Look at Line 23, there is your bad....
 
Share this answer
 
v2
Comments
Altaful Haq 28-Jul-15 3:49am    
can you make it right

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