DENTONE
5/8/2008 8:30:00 AM
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.
> =================================================
>