1
Answer

2 database connection in c#

raj aryan

raj aryan

12y
1.1k
1
Hello everyone,

I want to get data from an odbc connection and copy the data into sql server table. The scenario is like this, I want to open odbc connection, then get the data into something(actyally the data is in tabular format), then open the sql connection and then whatever the data we took from the odbc connection, want to dump(store) into sql server table or say just want to copy the odbc tabular format data into sql server database. please guide me something, I am new to c#.

Advance Thanks...
Raj
Answers (1)
0
Ken Barrett

Ken Barrett

NA 173 0 15y
Looks as if I figured it out.  It may not be the most elegant solution, but it seems to work.. and I understand it.

By number of entries  I meant that the number of entries that are in the guest book are variable. This depends on how many people have signed it.  So the number of entries that are shown on the view guest book page depends on how many people have signed the guest book.

The way I solved this was first to include a html span on the web page. As in :
<!-- start guest book entries -->
<span id="GBentries" runat=server></span>


Then I used a data reader (I like data readers because I'm old fashioned) to load only the date, name, and comments out of the data table. There's a lot more data in there, but I only want to display these items.  As in :
  private int getGBentries() {
    int rows = 0 ;
    string cmd = "SELECT Date, Name, Comments FROM dbo.Guest" ;
    using (SqlConnection gconn = new SqlConnection(dbConn))
    {
      try {
        gconn.Open() ;
        SqlCommand Scmd = new SqlCommand(cmd, gconn);
        SqlDataReader dr = Scmd.ExecuteReader() ;
        while(dr.Read()) {
          GuestEntry ge = new GuestEntry((DateTime)dr["Date"],
                            (string)dr["Name"],(string)dr["Comments"]) ;
          entries.Push(ge) ; // build a stack to be used later
          rows++ ;
        }
        dr.Close() ;
        gconn.Close() ;
        return(rows) ;
      } catch {
        return(0) ;
      }
    }
  }


As each item was read in a string object was appended with a new html table to hold that particular entry.  As in :
  private void buildEntries() {
    foreach (GuestEntry ge in entries) {
      guestOut +=
        "<table width=800 cellpadding=8>\n" +
        "  <tr><td colspan=2><hr /></td></tr>\n" +
        "  <tr>\n" +
        "    <td width=200>Date</td>\n" +
        "    <td width=600>" + ge.getCommentDate().Date + "</td>\n" +
        "  </tr>\n" +
        "  <tr>\n" +
        "    <td width=200>Name</td>\n" +
        "    <td width=600>" + ge.getName() + "</td>\n" +
        "  </tr>\n" +
        "  <tr>\n" +
        "    <td width=200>Comments</td>\n" +
        "    <td width=600>" + ge.getComment() + "</td>\n" +
        "  </tr>\n" +
        "</table>\n" ;
    }
  }


Then the string was written out to the span id on the web page. As in :
  protected void Page_Load(object sender, EventArgs e) {
    getGBentries() ;
    buildEntries() ;
    GBentries.InnerHtml = guestOut ;
  }

0
Roei Bar

Roei Bar

NA 7.8k 0 15y
by saying number of entries, do you want the number of entries in the Guestbook or the number of entries to that page?

the number of entries in the guestbook is easy, use databindNavigator it will give you all the data you return for you to manipulate and also you can know how many entries or more truly to say how many rows you have...

for number of entries to page you need  a counter control that you can download all over