[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

DENTONE

5/7/2008 3:25:00 PM

Dear newsgroup,

I have to make a gridview (in a web page) that show some data from a SQL DB,
but i want to populate this gridview from code (VB) and not from wizard
because the sql DB is not always the same but change in function of the name
of the user.
I have 10 user and for each one i have a DB named by the username,.

Thank's


9 Answers

jialge

5/8/2008 5:03:00 AM

0

Good morning DENTONE, welcome to Microsoft Newsgroup Support Service! My
name is Jialiang Ge (MSFT) and I will help you with this issue.

According to the post, you wonders how to write VB.NET code to bind a table
content to an ASP.NET GridView control. The DB of the table is dynamically
specified by the name of the user. If I'm off base, please feel free to let
me know.

To well demonstrate how to do this without ASP.NET GridView Wizard, I write
the following VB.NET code for your reference. I will explain the codes in
detail, so that you can have a clearer picture of how it works:

First, because the DB connection is dynamically determined by the current
user name, we need a function that can return the corresponding DB's
connection string for the user name:

Public Function GetConnectionString(ByVal userName As String) As String
'in this function, please customize it to fit your specific scenario
'if the username is exactly equals connectstring name, we can write the
function as
'Return ConfigurationManager.ConnectionStrings(userName).ConnectionString
If userName = "Tom" Then Return
ConfigurationManager.ConnectionStrings("TomConnStr").ConnectionString
If userName = "Jef" Then Return
ConfigurationManager.ConnectionStrings("JefConnStr").ConnectionString
Return
ConfigurationManager.ConnectionStrings("DefaultConnStr").ConnectionString
End Function

We can put the connection strings in web.config:
<connectionStrings>
<add name="TomConnStr" connectionString="Data Source=[servername];Initial
Catalog=[dbname];User ID=[userid];Password=[pwd]"
providerName="System.Data.SqlClient"/>
<add name=" JefConnStr" connectionString="Data Source=[servername];Initial
Catalog=[dbname];User ID=[userid];Password=[pwd]"
providerName="System.Data.SqlClient"/>
¡­¡­ other connection strings
</connectionStrings>

Second, we write a function to retrieve the table content:
The first parameter specifies the username, which will be used to determine
the DB connection. The second parameter is the table name in the DB.

Public Function GetDataTable(ByVal userName As String, ByVal tableName As
String) As DataTable
'build a SqlConnection object and open the connection to the DB specified
by userName
Dim conn As New SqlConnection(GetConnectionString(userName))
Try
conn.Open()
Dim dataSet1 As New DataSet("UserNameDS")
Dim dataAdapter As New SqlDataAdapter()
'the SQL select command
dataAdapter.SelectCommand = New SqlCommand("SELECT * FROM [" &
tableName & "]", conn)
dataAdapter.Fill(dataSet1, "UserNameDS")
Return dataSet1.Tables(0)
Catch ex As Exception
Throw ex
Finally
'close the connection
If conn.State = ConnectionState.Open Then conn.Close()
End Try
End Function

Now, to bind the table from GetDataTable to the GridView control, we do it
in this way:
Me.GridView1.DataSource = GetDataTable("Tom", "tblPeople")
Me.GridView1.DataBind()

This piece of binding code can be put in Page_Load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles Me.Load
If Not Page.IsPostBack Then
Me.GridView1.DataSource = GetDataTable("Tom", "tblPeople")
Me.GridView1.DataBind()
End If
End Sub

Or other places where we need to do the binding according to your specific
business logic.

So far, we've bound the DataSource to the GridView control. You did not
mention whether you planed to do paging/sorting/editing or not, if you want
to do it, the codeproject article:
http://www.codeproject.com/KB/aspnet/gridv...
has a good demonstration.

Let me know if the above walkthrough helps you and any other
questions/concerns you have. Also feel free to contact me directly with my
email, which can be found in my signature, so that we can discuss the issue
in a more efficient way.

Have a nice day!

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/de....
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

DENTONE

5/8/2008 6:52:00 AM

0

Thank's for the reply.
Only one question.. sorry but the name of the DB is not equal to the name of
the user but depend by it.
I take the name of the user and then i can associate it to a company.
Like "John" is user of company "SMI".
Thenk i have to bind the content of the gridview to the DB "SMI DB MERCI" .
If the user name is "Math" of company "GHIANDA" i have to bind it to
"GHIANDA DB MERCI".
I have just writed the code to read the company of the user and i have this
into a variable called "AGENZIA".
So i have only to make the connectionstring.
But it is difficalt to but all the connection string in the webconfig
because the number of company change in time, because i i have a new company
i make the new DB and i want the code not to change.
I hope i explain the problem to you because my english is not very good.

Thank's


"Jialiang Ge [MSFT]" <jialge@online.microsoft.com> ha scritto nel messaggio
news:t%23TUdjMsIHA.1900@TK2MSFTNGHUB02.phx.gbl...
> Good morning DENTONE, welcome to Microsoft Newsgroup Support Service! My
> name is Jialiang Ge (MSFT) and I will help you with this issue.
>
> According to the post, you wonders how to write VB.NET code to bind a
> table
> content to an ASP.NET GridView control. The DB of the table is dynamically
> specified by the name of the user. If I'm off base, please feel free to
> let
> me know.
>
> To well demonstrate how to do this without ASP.NET GridView Wizard, I
> write
> the following VB.NET code for your reference. I will explain the codes in
> detail, so that you can have a clearer picture of how it works:
>
> First, because the DB connection is dynamically determined by the current
> user name, we need a function that can return the corresponding DB's
> connection string for the user name:
>
> Public Function GetConnectionString(ByVal userName As String) As String
> 'in this function, please customize it to fit your specific scenario
> 'if the username is exactly equals connectstring name, we can write the
> function as
> 'Return ConfigurationManager.ConnectionStrings(userName).ConnectionString
> If userName = "Tom" Then Return
> ConfigurationManager.ConnectionStrings("TomConnStr").ConnectionString
> If userName = "Jef" Then Return
> ConfigurationManager.ConnectionStrings("JefConnStr").ConnectionString
> Return
> ConfigurationManager.ConnectionStrings("DefaultConnStr").ConnectionString
> End Function
>
> We can put the connection strings in web.config:
> <connectionStrings>
> <add name="TomConnStr" connectionString="Data Source=[servername];Initial
> Catalog=[dbname];User ID=[userid];Password=[pwd]"
> providerName="System.Data.SqlClient"/>
> <add name=" JefConnStr" connectionString="Data Source=[servername];Initial
> Catalog=[dbname];User ID=[userid];Password=[pwd]"
> providerName="System.Data.SqlClient"/>
> ¡­¡­ other connection strings
> </connectionStrings>
>
> Second, we write a function to retrieve the table content:
> The first parameter specifies the username, which will be used to
> determine
> the DB connection. The second parameter is the table name in the DB.
>
> Public Function GetDataTable(ByVal userName As String, ByVal tableName As
> String) As DataTable
> 'build a SqlConnection object and open the connection to the DB specified
> by userName
> Dim conn As New SqlConnection(GetConnectionString(userName))
> Try
> conn.Open()
> Dim dataSet1 As New DataSet("UserNameDS")
> Dim dataAdapter As New SqlDataAdapter()
> 'the SQL select command
> dataAdapter.SelectCommand = New SqlCommand("SELECT * FROM [" &
> tableName & "]", conn)
> dataAdapter.Fill(dataSet1, "UserNameDS")
> Return dataSet1.Tables(0)
> Catch ex As Exception
> Throw ex
> Finally
> 'close the connection
> If conn.State = ConnectionState.Open Then conn.Close()
> End Try
> End Function
>
> Now, to bind the table from GetDataTable to the GridView control, we do it
> in this way:
> Me.GridView1.DataSource = GetDataTable("Tom", "tblPeople")
> Me.GridView1.DataBind()
>
> This piece of binding code can be put in Page_Load:
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
> Handles Me.Load
> If Not Page.IsPostBack Then
> Me.GridView1.DataSource = GetDataTable("Tom", "tblPeople")
> Me.GridView1.DataBind()
> End If
> End Sub
>
> Or other places where we need to do the binding according to your specific
> business logic.
>
> So far, we've bound the DataSource to the GridView control. You did not
> mention whether you planed to do paging/sorting/editing or not, if you
> want
> to do it, the codeproject article:
> http://www.codeproject.com/KB/aspnet/gridv...
> has a good demonstration.
>
> Let me know if the above walkthrough helps you and any other
> questions/concerns you have. Also feel free to contact me directly with my
> email, which can be found in my signature, so that we can discuss the
> issue
> in a more efficient way.
>
> Have a nice day!
>
> Regards,
> Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/de....
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>


jialge

5/8/2008 8:02:00 AM

0

Hello DENTONE,

>I hope i explain the problem to you because my english is not
> very good.
No problem, DENTONE. I can understand your messages. In fact, I am not a
native English speaker, either. :-)

>But it is difficalt to but all the connection string in the
> webconfig because the number of company change in time,
> because i have a new company i make the new DB and i want
> the code not to change.

I think we have two solutions here:

Solution 1.

We still use web.config to store all the connection strings and this won't
require the change of code or the compilation/redistribution of the web
project when we need to add/edit companies. Let me explain it in detail.

First, we write the GetConnectionString as this:

Public Function GetConnectionString(ByVal userName As String) As String
'1. we get the company of the user (as you mentioned, you've
written the part for GetCompany)
Dim AGENZIA As String = GetCompany(userName)
'2. get the connection string according to the company name
Return ConfigurationManager.ConnectionStrings(AGENZIA & " DB
MERCI").ConnectionString
End Function

Second, we put all the connection strings into web.config:

<connectionStrings>
<add name="SMI DB MERCI" connectionString="Data
Source=[servername];Initial Catalog=[SMI DB MERCI];User
ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
<add name=" GHIANDA DB MERCI" connectionString="Data
Source=[servername];Initial Catalog=[GHIANDA DB MERCI];User
ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
</connectionStrings>

Now, suppose we've distributed the web project to the server, and need to
add a new DB named "FORTEST", we do not need to change any code (e.g.
GetConnectionString) or redistribute the project. What we need to do is to
open web.config, add a new entry:
<add name=" FORTEST DB MERCI" connectionString="Data
Source=[servername];Initial Catalog=[ FORTEST DB MERCI];User
ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
Into connectionStrings, save and close web.config. Then everything is done.
GetConnectionString will automatically find the new connection string with
the code line Return ConfigurationManager.ConnectionStrings(AGENZIA & " DB
MERCI").ConnectionString.

Solution 2.

If you still feel uncomfortable with web.config, we can move the
connectionStrings from web.config to a DB table. The DB table stores the
same pairs: name <-> connectionString. And in GetConnectionString, we query
the connectionString value according to the company name from the DB table.

Suppose we need to add a new company, we can add the entry in the DB table,
and everything is done too.

Are the solutions easy to be followed? Let me know if you have any other
concerns or questions.

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

DENTONE

5/8/2008 8:30:00 AM

0

Thank's i have solved by solution 2.
I have another question:
this is my code:
Imports system.Data.SqlClient

Partial Public Class DATI_VIAGGIO_COLLI

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim nometabella As String


nometabella = "[" + Session("agenzia") + " di " + Session("porto") + " db
merci" + "]"

Me.GridView1.DataSource = GetDataTable("Tom", nometabella)

Me.GridView1.DataBind()

End Sub

Public Function GetDataTable(ByVal userName As String, ByVal tableName As
String) As DataTable

' Dim connstring As String = "Data Source=[server];Initial
Catalog=[master];User ID=[HACPACK];Password=[francesca]"

Dim connstring As String = "Data Source=serverhacpack;Initial
Catalog=master;User ID=HACPACK;Password=francesca"

Dim conn As New SqlConnection((connstring))

conn.Open()

Dim dataSet1 As New DataSet("MERCI")

Dim dataAdapter As New SqlDataAdapter()

dataAdapter.SelectCommand = New SqlCommand("SELECT
[sostanza],[ONU],[CLASSE1],[PG],[EMS] FROM " + tableName + " Where
([NAVE]='" + Session("nave") + "' AND [IDVIAGGIO]='" + Session("id") + "')",
conn)

dataAdapter.Fill(dataSet1, "MERCI")

Return dataSet1.Tables(0)

End Function

End Class



So i have in the gridview the colums sostanza, ONU, etc ect from the table.

If i want to change the header of the colums how i can?

I need to change the headers like sostanza to SOSTANZA, PG to Packing Group
.... erc etc...

And i want to leave the DB table fileds inalterate!



thank's

"Jialiang Ge [MSFT]" <jialge@online.microsoft.com> ha scritto nel messaggio
news:gKozIHOsIHA.1856@TK2MSFTNGHUB02.phx.gbl...
> Hello DENTONE,
>
>>I hope i explain the problem to you because my english is not
>> very good.
> No problem, DENTONE. I can understand your messages. In fact, I am not a
> native English speaker, either. :-)
>
>>But it is difficalt to but all the connection string in the
>> webconfig because the number of company change in time,
>> because i have a new company i make the new DB and i want
>> the code not to change.
>
> I think we have two solutions here:
>
> Solution 1.
>
> We still use web.config to store all the connection strings and this won't
> require the change of code or the compilation/redistribution of the web
> project when we need to add/edit companies. Let me explain it in detail.
>
> First, we write the GetConnectionString as this:
>
> Public Function GetConnectionString(ByVal userName As String) As String
> '1. we get the company of the user (as you mentioned, you've
> written the part for GetCompany)
> Dim AGENZIA As String = GetCompany(userName)
> '2. get the connection string according to the company name
> Return ConfigurationManager.ConnectionStrings(AGENZIA & " DB
> MERCI").ConnectionString
> End Function
>
> Second, we put all the connection strings into web.config:
>
> <connectionStrings>
> <add name="SMI DB MERCI" connectionString="Data
> Source=[servername];Initial Catalog=[SMI DB MERCI];User
> ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
> <add name=" GHIANDA DB MERCI" connectionString="Data
> Source=[servername];Initial Catalog=[GHIANDA DB MERCI];User
> ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
> </connectionStrings>
>
> Now, suppose we've distributed the web project to the server, and need to
> add a new DB named "FORTEST", we do not need to change any code (e.g.
> GetConnectionString) or redistribute the project. What we need to do is to
> open web.config, add a new entry:
> <add name=" FORTEST DB MERCI" connectionString="Data
> Source=[servername];Initial Catalog=[ FORTEST DB MERCI];User
> ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
> Into connectionStrings, save and close web.config. Then everything is
> done.
> GetConnectionString will automatically find the new connection string with
> the code line Return ConfigurationManager.ConnectionStrings(AGENZIA & " DB
> MERCI").ConnectionString.
>
> Solution 2.
>
> If you still feel uncomfortable with web.config, we can move the
> connectionStrings from web.config to a DB table. The DB table stores the
> same pairs: name <-> connectionString. And in GetConnectionString, we
> query
> the connectionString value according to the company name from the DB
> table.
>
> Suppose we need to add a new company, we can add the entry in the DB
> table,
> and everything is done too.
>
> Are the solutions easy to be followed? Let me know if you have any other
> concerns or questions.
>
> Regards,
> Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> =================================================
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@microsoft.com.
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> =================================================
>


DENTONE

5/8/2008 8:33:00 AM

0

Sorry i have also this error:


Errore server nell'applicazione '/'.
--------------------------------------------------------------------------------

L'evento PageIndexChanging generato dal GridView 'GridView1' non gestito.
Descrizione: Eccezione non gestita durante l'esecuzione della richiesta Web
corrente. Per ulteriori informazioni sull'errore e sul suo punto di origine
nel codice, vedere l'analisi dello stack.

Dettagli eccezione: System.Web.HttpException: L'evento PageIndexChanging
generato dal GridView 'GridView1' non gestito.

Errore nel codice sorgente:

Durante l'esecuzione della richiesta Web corrente è stata generata
un'eccezione non gestita. Per informazioni sull'origine e la posizione
dell'eccezione, vedere l'analisi dello stack dell'eccezione riportata di
seguito.

Analisi dello stack:

[HttpException (0x80004005): L'evento PageIndexChanging generato dal
GridView 'GridView1' non gestito.]
System.Web.UI.WebControls.GridView.OnPageIndexChanging(GridViewPageEventArgs
e) +1495955
System.Web.UI.WebControls.GridView.HandlePage(Int32 newPage) +83
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +467
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String
eventArgument) +199
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746



--------------------------------------------------------------------------------
Informazioni di versione: Versione di Microsoft .NET
Framework:2.0.50727.1433; Versione di ASP.NET:2.0.50727.1433
"Jialiang Ge [MSFT]" <jialge@online.microsoft.com> ha scritto nel messaggio
news:gKozIHOsIHA.1856@TK2MSFTNGHUB02.phx.gbl...
> Hello DENTONE,
>
>>I hope i explain the problem to you because my english is not
>> very good.
> No problem, DENTONE. I can understand your messages. In fact, I am not a
> native English speaker, either. :-)
>
>>But it is difficalt to but all the connection string in the
>> webconfig because the number of company change in time,
>> because i have a new company i make the new DB and i want
>> the code not to change.
>
> I think we have two solutions here:
>
> Solution 1.
>
> We still use web.config to store all the connection strings and this won't
> require the change of code or the compilation/redistribution of the web
> project when we need to add/edit companies. Let me explain it in detail.
>
> First, we write the GetConnectionString as this:
>
> Public Function GetConnectionString(ByVal userName As String) As String
> '1. we get the company of the user (as you mentioned, you've
> written the part for GetCompany)
> Dim AGENZIA As String = GetCompany(userName)
> '2. get the connection string according to the company name
> Return ConfigurationManager.ConnectionStrings(AGENZIA & " DB
> MERCI").ConnectionString
> End Function
>
> Second, we put all the connection strings into web.config:
>
> <connectionStrings>
> <add name="SMI DB MERCI" connectionString="Data
> Source=[servername];Initial Catalog=[SMI DB MERCI];User
> ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
> <add name=" GHIANDA DB MERCI" connectionString="Data
> Source=[servername];Initial Catalog=[GHIANDA DB MERCI];User
> ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
> </connectionStrings>
>
> Now, suppose we've distributed the web project to the server, and need to
> add a new DB named "FORTEST", we do not need to change any code (e.g.
> GetConnectionString) or redistribute the project. What we need to do is to
> open web.config, add a new entry:
> <add name=" FORTEST DB MERCI" connectionString="Data
> Source=[servername];Initial Catalog=[ FORTEST DB MERCI];User
> ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
> Into connectionStrings, save and close web.config. Then everything is
> done.
> GetConnectionString will automatically find the new connection string with
> the code line Return ConfigurationManager.ConnectionStrings(AGENZIA & " DB
> MERCI").ConnectionString.
>
> Solution 2.
>
> If you still feel uncomfortable with web.config, we can move the
> connectionStrings from web.config to a DB table. The DB table stores the
> same pairs: name <-> connectionString. And in GetConnectionString, we
> query
> the connectionString value according to the company name from the DB
> table.
>
> Suppose we need to add a new company, we can add the entry in the DB
> table,
> and everything is done too.
>
> Are the solutions easy to be followed? Let me know if you have any other
> concerns or questions.
>
> Regards,
> Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> =================================================
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@microsoft.com.
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> =================================================
>


jialge

5/8/2008 10:15:00 AM

0

Hello DENTONE,

To customize the appearance, e.g. the header of columns, we can use the
GridView's wizard. (note this wizard is different from the one for
configuring data source):

Step1. Go to the aspx page designer in VS, set the GridView's
AutoGenerateColumns property to 'False'.
Step2. Click on the little angle on the right-upper side of GridView. In
the GridView Tasks dialog, click "Edit Columns".
Step3. In the "Fields" dialog that is popped up, add a fields (e.g.
BoundField). In the field's properties page, input our header (e.g.
"SOSTANZA") in the "HeaderText" property. And in the "DataField", input the
field name in the datatable which is returned by GetDataTable (e.g.
"sostanza").
Step4. Repeat step3 for all the fields we want to display in the GridView.

The resulting aspx code for the GridView looks like this:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="sostanza" HeaderText="SOSTANZA" />
<asp:BoundField DataField="PG" HeaderText="Packing Group" />
</Columns>
</asp:GridView>

Please try it and let me know if it helps.

>And i want to leave the DB table fileds inalterate!
Sorry, what do you mean by "fileds inalterate"?

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

DENTONE

5/8/2008 10:15:00 AM

0

SOLVED ,

Thank's I have solved all the problems regard this !!
"DENTONE" <dinodentone@community.nospam> ha scritto nel messaggio
news:eXqudYOsIHA.4376@TK2MSFTNGP06.phx.gbl...
> Sorry i have also this error:
>
>
> Errore server nell'applicazione '/'.
> --------------------------------------------------------------------------------
>
> L'evento PageIndexChanging generato dal GridView 'GridView1' non gestito.
> Descrizione: Eccezione non gestita durante l'esecuzione della richiesta
> Web corrente. Per ulteriori informazioni sull'errore e sul suo punto di
> origine nel codice, vedere l'analisi dello stack.
>
> Dettagli eccezione: System.Web.HttpException: L'evento PageIndexChanging
> generato dal GridView 'GridView1' non gestito.
>
> Errore nel codice sorgente:
>
> Durante l'esecuzione della richiesta Web corrente è stata generata
> un'eccezione non gestita. Per informazioni sull'origine e la posizione
> dell'eccezione, vedere l'analisi dello stack dell'eccezione riportata di
> seguito.
>
> Analisi dello stack:
>
> [HttpException (0x80004005): L'evento PageIndexChanging generato dal
> GridView 'GridView1' non gestito.]
>
> System.Web.UI.WebControls.GridView.OnPageIndexChanging(GridViewPageEventArgs
> e) +1495955
> System.Web.UI.WebControls.GridView.HandlePage(Int32 newPage) +83
> System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
> causesValidation, String validationGroup) +467
> System.Web.UI.WebControls.GridView.RaisePostBackEvent(String
> eventArgument) +199
>
> System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
> eventArgument) +7
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
> sourceControl, String eventArgument) +11
> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
> System.Web.UI.Page.ProcessRequestMain(Boolean
> includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
>
>
>
> --------------------------------------------------------------------------------
> Informazioni di versione: Versione di Microsoft .NET
> Framework:2.0.50727.1433; Versione di ASP.NET:2.0.50727.1433
> "Jialiang Ge [MSFT]" <jialge@online.microsoft.com> ha scritto nel
> messaggio news:gKozIHOsIHA.1856@TK2MSFTNGHUB02.phx.gbl...
>> Hello DENTONE,
>>
>>>I hope i explain the problem to you because my english is not
>>> very good.
>> No problem, DENTONE. I can understand your messages. In fact, I am not a
>> native English speaker, either. :-)
>>
>>>But it is difficalt to but all the connection string in the
>>> webconfig because the number of company change in time,
>>> because i have a new company i make the new DB and i want
>>> the code not to change.
>>
>> I think we have two solutions here:
>>
>> Solution 1.
>>
>> We still use web.config to store all the connection strings and this
>> won't
>> require the change of code or the compilation/redistribution of the web
>> project when we need to add/edit companies. Let me explain it in detail.
>>
>> First, we write the GetConnectionString as this:
>>
>> Public Function GetConnectionString(ByVal userName As String) As
>> String
>> '1. we get the company of the user (as you mentioned, you've
>> written the part for GetCompany)
>> Dim AGENZIA As String = GetCompany(userName)
>> '2. get the connection string according to the company name
>> Return ConfigurationManager.ConnectionStrings(AGENZIA & " DB
>> MERCI").ConnectionString
>> End Function
>>
>> Second, we put all the connection strings into web.config:
>>
>> <connectionStrings>
>> <add name="SMI DB MERCI" connectionString="Data
>> Source=[servername];Initial Catalog=[SMI DB MERCI];User
>> ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
>> <add name=" GHIANDA DB MERCI" connectionString="Data
>> Source=[servername];Initial Catalog=[GHIANDA DB MERCI];User
>> ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
>> </connectionStrings>
>>
>> Now, suppose we've distributed the web project to the server, and need to
>> add a new DB named "FORTEST", we do not need to change any code (e.g.
>> GetConnectionString) or redistribute the project. What we need to do is
>> to
>> open web.config, add a new entry:
>> <add name=" FORTEST DB MERCI" connectionString="Data
>> Source=[servername];Initial Catalog=[ FORTEST DB MERCI];User
>> ID=[userid];Password=[pwd]" providerName="System.Data.SqlClient"/>
>> Into connectionStrings, save and close web.config. Then everything is
>> done.
>> GetConnectionString will automatically find the new connection string
>> with
>> the code line Return ConfigurationManager.ConnectionStrings(AGENZIA & "
>> DB
>> MERCI").ConnectionString.
>>
>> Solution 2.
>>
>> If you still feel uncomfortable with web.config, we can move the
>> connectionStrings from web.config to a DB table. The DB table stores the
>> same pairs: name <-> connectionString. And in GetConnectionString, we
>> query
>> the connectionString value according to the company name from the DB
>> table.
>>
>> Suppose we need to add a new company, we can add the entry in the DB
>> table,
>> and everything is done too.
>>
>> Are the solutions easy to be followed? Let me know if you have any other
>> concerns or questions.
>>
>> Regards,
>> Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
>> Microsoft Online Community Support
>>
>> =================================================
>> Delighting our customers is our #1 priority. We welcome your comments and
>> suggestions about how we can improve the support we provide to you.
>> Please
>> feel free to let my manager know what you think of the level of service
>> provided. You can send feedback directly to my manager at:
>> msdnmg@microsoft.com.
>>
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> =================================================
>>
>
>


jialge

5/8/2008 10:35:00 AM

0

Hello DENTONE,

Although I do not understand the error message because they are not in
English (is it French or German? :-)), the word "PageIndexChanging" tells
me that the error is thrown from the paging mechanism of GridView. Would
you paste some code about how you do the paging? Below is a step list with
which I used to do paging for GridView. You can refer to it and see if it
works for you:

Step1. Set GridView's AllowPaging property to true.
Step2. Register GridView's PageIndexChanging event
Step3. In the event handler, add the following piece of code:

GridView1.PageIndex = e.NewPageIndex
GridView1.DataSource = GetDataTable(¡­ ¡­)
GridView1.DataBind()

Let me know if you have any other questions or concerns.

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

jialge

5/8/2008 10:39:00 AM

0

You are welcome, DENTONE. It's my pleasure to help. :-)

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================