Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
H

Horscht i

@Horscht i
About
Posts
8
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Export to Excel
    H Horscht i

    I post my code, if anyone has also problems with Excel export: string FileName = "";// Filename for opening and saving object ReadOnly = false; object IsVisible = true; object ExcelSheet; object FileFilter = "Microsoft Excel (*.xls), *.xls"; // Use for parameters you do not want do declare or do not know :-) object missing = System.Reflection.Missing.Value; // Params for AutoFormat object format_true = true; object format_false = false; Excel.ApplicationClass ExcelApp = new Excel.ApplicationClass(); try { // Open a new workbook Excel.Workbook ExcelBook = ExcelApp.Workbooks.Add(missing); ExcelSheet = ExcelBook.Worksheets.get_Item(1); ExcelBook.Activate(); int ExcelRow = 4; int ExcelCol = 1; //Write column names while (ExcelCol < GridView_Name.Columns.Count - 1) { ExcelApp.Cells[ExcelRow, ExcelCol] = GridView_Name.Columns[ExcelCol].ToString(); ExcelCol++; } // Write data ExcelRow = 5; ExcelCol = 1; int row = 0; while (row < GridView_Name.Rows.Count) { while (ExcelCol < GridView_Name.Columns.Count - 2) { ExcelApp.Cells[ExcelRow + row, ExcelCol] = GridView_Name.Rows[row].Cells[ExcelCol].Text.ToString().Trim(); ExcelCol++; } row++; ExcelCol = 1; } // switch statement which selects the right functions of Excel according to the installed version of Excel on the client computer. // Only AutoFormat, SaveAs and Quit functions are used, so this switch statement is at the end of this Export2Excel function. switch (ExcelApp.Version.ToString()) { case "9.0": // Format workbook using Excel AutoFormats ExcelApp.get_Range("A1", missing).AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormatList3, format_true, format_true, format_false, format_true, format_true, format_false); ExcelApp.get_Range("A4", missing).AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormatList1, format_true, format_true, format_false, format_true, format_true, format_false);

    ASP.NET wpf wcf design help

  • Export to Excel
    H Horscht i

    Those are the articles I have the above code snippet from... so I tried something else and it works. Thanks for your help!

    ASP.NET wpf wcf design help

  • Export to Excel
    H Horscht i

    Hello! Most of you are familiar with this piece of code which exports a GridView/DetailsView etc. to Excel: protected void Export2ExcelClick(object sender, EventArgs e) { Response.Clear(); Response.Buffer = true; Response.AppendHeader("content-disposition", "inline; filename=test.xls"); Response.ContentType = "application/ms-excel"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); GridView_EffortCostsOverview.RenderControl(htmlWrite); Response.End(); } I have bound the GridView to an SqlDataSource in .aspx file. I tried binding it dynamically in CodeBehing, but the problem remained the same: Not only the GridView is exported, the code exports the whole webform to an excel sheet, so the htmlWriter seems to be full with the hole webform... But the writer is first generated in this Export2ExcelClick function. It does not appear anywhere else. A quick solution will be highly appreciated!

    ASP.NET wpf wcf design help

  • Binding SqlDataReader to GridView
    H Horscht i

    I think you did not get my intention... With the DropDownList the user can select, what he wants to search for: If he wants to search for a project title, than he chooses "ProjectTitle" from the List. (The items of the list are exactly the column names). Then the user enters the string he wants to search for in a beneath TextBox. @SearchValue parameter will be TextBox.Text Thus, we have as SELECT command: "[...] WHERE (['"+DropDownList.SelectedValue+"'] LIKE '%@SearchValue%')" just as you described. Or to get rid of the parameter "[...] WHERE (['"+DropDownList.SelectedValue+"'] LIKE '%'"+TextBox.Text"'%')" ['"+DropDownList.SelectedValue+"'] produces the error message 'Invalid column name "ProjectTitle"', but ProjectTitle is exactly the column name. That is what i do not understand. If i hard code the column name, e.g. "[...] WHERE ([ProjectTitle] LIKE '%'"+TextBox.Text+"'%')" the code works. DropDownList.SelectedItem and DropDownList.Text also produce the same error message. The problem is, that the selected item of the list is not properly inserted into the SELECT command and i don`t know why.:sigh:

    ASP.NET help database wpf wcf tutorial

  • Binding SqlDataReader to GridView
    H Horscht i

    Now I am one step closer. It works, but i reveive an error message "Invalid column name [Text Of DropDownList]". But at least the query was send to db. Thanks albcode!

    ASP.NET help database wpf wcf tutorial

  • how to retreave data?
    H Horscht i

    If the problem is that the TextBoxes don`t get filled with data (this was my problem few days ago), try: SqlDataReader Reader = null; SqlConn.Open(); Reader = SelectData.ExecuteReader(); while (Reader.Read()) { Txt_ProjectTitle.Text = Convert.ToString(Reader[1]).Trim(); ButtonListProjectType.SelectedValue = Convert.ToString(Reader[2]); DropDownList_ProjectStatus.SelectedValue = Convert.ToString(Reader[3]); [and so on...] } Reader.Close(); SqlConn.Close(); It is C# code though, but should be easy to read. I think you just have to put this while loop around the if/else commands. while (dr.Read()) { If dr.HasRows = False Then ' error mesej Else txtnama.Text = CInt(dr("nama")) txtjawatan.Text = CInt(dr("jawatan")) txtjabatan.Text = CInt(dr("jabatan")) txtbidang.Text = CInt(dr("jabatan")) txtjabatan.Text = CInt(dr("jabatan")) End If Else 'error } -- modified at 7:54 Tuesday 14th March, 2006

    ASP.NET database help tutorial question

  • Binding SqlDataReader to GridView
    H Horscht i

    I am using BoundFields in the GridView. I`ll try with auto generated fields...maybe it works. -- modified at 2:35 Tuesday 14th March, 2006 No, BoundFields were not the problem. As I said it works fine, if I hard code a value like [...] WHERE ([ProjectID] LIKE @SearchValue)" For [ProjectID] I want to have the user selection of the DropDownList.

    ASP.NET help database wpf wcf tutorial

  • Binding SqlDataReader to GridView
    H Horscht i

    Hi guys, this is the code I have problems with. It is supposed to become a little search function when finished. private void InitSearch() { DropDownList_SearchWhat.Items.Add("[ProjectID]"); [...] } protected void PerformSearch(object sender, EventArgs e) { //Start Sql connection using connection string from web.config SqlConnection SqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["String"].ToString()); // Define Search command SqlCommand Search = new SqlCommand(); Search.Connection = SqlConn; SqlDataReader Reader = null; Search.Parameters.Add(new SqlParameter("@SearchValue", Txt_SearchValue.Text.Trim())); Search.CommandText = "SELECT [ProjectID], [ProjectTitle], [ProjectStatus], [Orderer] FROM [DevelopmentOrder] WHERE ('"+DropDownList_SearchWhat.Text.Trim()+"'=@SearchValue)"; try { SqlConn.Open(); Reader = Search.ExecuteReader(); GVOverview.DataSource = Reader; GVOverview.DataBind(); Reader.Close(); SqlConn.Close(); } catch (Exception ex) { Message.Text = ex.Message; SqlConn.Close(); } The code works fine without any error message, but nothing is displayed in the GridView "GVOverview". I think the problem is the SELECT command: With the DropDownList the user can choose, what he wants to search for (Project ID, Type, Title). The search string can be typed into the TextBox "Txt_SearchValue". The DropDownList items are equal to the column names of the table, so i use the DropDownList.Text attribute to build the SELECT command. I also tried using an additional SqlParameter: "SELECT [ProjectID], [ProjectTitle], [ProjectStatus], [Orderer] FROM [DevelopmentOrder] WHERE (@SearchWhat = @SearchValue)"; In this case the @SearchWhat parameter text depends on the selected item in the DropDownList, e.g. if (DropDownList.SelectedIndex == 0) { Search.Parameters.Add(new SqlParameter("@SearchWhat", "[ProjectID]")); } The result is the same: Nothing is displayed in the GridView. Only way it displays something is a hard coded column name in the WHERE statement (e.g. WHERE [ProjectID]=@SelectValue). Has anyone an idea how to fix this problem? Thanks in advance PS: I guess there exist several better ways to programm a search func

    ASP.NET help database wpf wcf tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups