Click here to Skip to main content
15,912,457 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
actually i m using visual studio 2012 i m a fresher sir
i m using class library for making a dll file for re-usability in to another ,
simply i want to display a table record in to gridview in the web form.
almost i tried 3rd solutions but its also not working in system


please see error and code

C#
{
    public class mycomponent
    {
        public DataSet getdata(string s)
        {
            SqlConnection con = new SqlConnection("userid = sa; password=123; database=inventory123; datasource=ICONLABS2-PC");
            SqlDataAdapter da = new SqlDataAdapter(s, con);
            DataSet ds = new DataSet();
            da.Fill(ds,"t");
            return(ds);  

        }
    }
}
this is website app


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        databaselogic.mycomponent obj = new databaselogic.mycomponent();
        DataSet ds = obj.getdata("select * from customers");

        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
        
    }
}




i got this error.
ERRORS:

Keyword not supported: 'userid'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Keyword not supported: 'userid'.

Source Error:


Line 12: {
Line 13: databaselogic.mycomponent obj = new databaselogic.mycomponent();
Line 14: DataSet ds = obj.getdata("select * from customers");
Line 15:
Line 16: GridView1.DataSource = ds.Tables[0];

Source File: e:\gnani\websites\databaselogicsite\Default.aspx.cs Line: 14

Stack Trace:


C#
[ArgumentException: Keyword not supported: 'userid'.]
   System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +5327300
   System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +95
   System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +59
   System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
   System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +167
   System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) +61
   System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +66
   System.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential) +26
   System.Data.SqlClient.SqlConnection..ctor(String connectionString) +6
   databaselogic.mycomponent.getdata(String s) +87
   _Default.Page_Load(Object sender, EventArgs e) in e:\gnani\websites\databaselogicsite\Default.aspx.cs:14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929


please help me for this problem
Posted
Updated 25-Dec-13 23:30pm
v7
Comments
These are Errors while building or Exceptions while running?

First of all, always Bind GridView by checking IsPostBack Property[^].
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        databaselogic.mycomponent obj = new databaselogic.mycomponent();
        DataSet ds = obj.getdata("select * from customers");
    
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
    }
}

Now, let's correct the ConnectionString, which is wrong in your code.

Change the below line of code...
C#
SqlConnection con = new SqlConnection("userid = sa; password=123; database=inventory123; datasource=ICONLABS2-PC");

to...
C#
SqlConnection con = new SqlConnection("Server=ICONLABS2-PC;Database=inventory123;User Id=sa;
Password=123;");


After all these, debug your code and see what is happening on each step.
 
Share this answer
 
Comments
gnani_pal 26-Dec-13 3:05am    
{now i m getting this error sir

Line 27: databaselogic.mycomponent obj = new databaselogic.mycomponent();
Line 28: DataSet ds = obj.getdata("select * from customers");
Line 29:
Line 30: GridView1.DataSource = ds.Tables[0];
When you come to below line...

Line 28: DataSet ds = obj.getdata("select * from customers");

Press F11, it will take you inside the getdata method. Then continue debugging by F10 inside getdata.
gnani_pal 26-Dec-13 3:08am    
please sir
gnani_pal 26-Dec-13 5:32am    
still error coming
actually how we ll get datasource name or code in my system
Did you debug inside "getdata" method? On which line exactly it threw Exception inside that method?
Are you sure you used User Id insted userid. Because i able to see this string
SqlConnection con = new SqlConnection("userid = sa; password=123; database=inventory123; datasource=ICONLABS2-PC");


also use Data source instead of datasource. below is standard format of connection string.
please check that.
C#
Dim str As String
str = "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"
 
Share this answer
 
Go to "services.msc" and check the service name which is given by you during sql installation.

datasource->computername\servicename,portno
 
Share this answer
 
v2
Comments
gnani_pal 26-Dec-13 2:40am    
my computer name is iconlabs2-PC
Ganesh Raja 26-Dec-13 2:57am    
what is the name/ip you giving while connecting through sql management studio?
else give .[dot] or localhost

Data Source=.;Database=master; User Id=sa;Password=password
try conenctionstring of format Server=myServerAddress;Database=myDataBase;User Id=myUsername;
Password=myPassword;
 
Share this answer
 
Comments
gnani_pal 26-Dec-13 2:33am    
where should i write this code, actually i given like this
("userid = sa; password=123; database=inventory123; datasource=ICONLABS2-PC");
hi Try this..

C#
SqlConnection con = new SqlConnection("Data Source=ICONLABS2-PC;Initial Catalog=inventory123;User Id=sa;Password=123;");
               SqlCommand cmd = new SqlCommand("select * from your_table_name", con);
               SqlDataAdapter da = new SqlDataAdapter(cmd);
               DataSet ds = new DataSet();
               con.Open();
               cmd.ExecuteNonQuery();
               da.Fill(ds);
               con.Close();
                return (ds);



check the connection string format:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx[^]
 
Share this answer
 
v3
Comments
gnani_pal 26-Dec-13 4:25am    
now i got this error sir

Server Error in '/' Application.

Keyword not supported: 'userid'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Keyword not supported: 'userid'.

Source Error:


Line 27: databaselogic.mycomponent obj = new databaselogic.mycomponent();
Line 28: //DataSet ds = new DataSet();
Line 29: DataSet ds = obj.getdata("select * from flctable");
Line 30:
Line 31: GridView1.DataSource = ds.Tables["t"];

Source File: e:\gnani\websites\WebSite1\Default.aspx.cs Line: 29

Stack Trace:


[ArgumentException: Keyword not supported: 'userid'.]
System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +5327300
System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +95
System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +59
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +167
System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) +61
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +66
System.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential) +26
System.Data.SqlClient.SqlConnection..ctor(String connectionString) +6
databaselogic.mycomponent.getdata(String s) +96
_Default.Page_Load(Object sender, EventArgs e) in e:\gnani\websites\WebSite1\Default.aspx.cs:29
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
gnani_pal 26-Dec-13 4:28am    
please tell me sir give me any answers
Karthik_Mahalingam 26-Dec-13 4:48am    
"Data Source=ICONLABS2-PC;Initial Catalog=inventory123;User Id=sa;Password=123;"
Karthik_Mahalingam 26-Dec-13 4:49am    
try my updated solution...
King Fisher 26-Dec-13 6:05am    
take out your code at page load and try the solution 4,it will work

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