I was given an assignment to parse out a text file, without a header record, using only a handful of the 300+ fields supplied. Since there is no header record to define the fields as in a CSV file, I was given these preliminary instructions after creating the HTML page using the file upload control and a few labels and such:
1- create a data table
2- add the columns I want to use to the table
3- save the uploaded file
4- define a stream reader
5- read each row and use MID to extract the data I need
6- write this data to the data table
7- display all the records in a grid view
I've managed to get to step #7 and that's where I'm having trouble. When I look at the data in the grid view, all the fields are in one column, the first column.
I had a little trouble earlier on and a colleague told me to concatenate the parsed fields using a comma and double quotes ("fld1","fld2","fld3"...) which sounded odd but I listened and now, I realize he was leading me down the wrong path.
So:
I used "Dim dtWork as New DataTable"
then "dtWork.Columns.Add("Lastname") for each column I wanted
then saved the file "Dim sPath As Sting="C:..."
defined a stream reader "Dim rdr As New StreamReader(sPath)
Read the rows "Dim sCurrentRow As String = rdr.ReadLine"
and parsed the data "Dim sLastName As String = Mid(sCurrentROw, 3, 25)"
did this for all my fields I wanted and then concatenated each field as described above into a string "Dim sData As String = sLastName & "," & sFirstName & ","....
and added it to the data table "dtWork.Rows.Add(sData)"
So that's the jist of it sans the datasource = dtWork and then the databind. Now, how do I get each parsed field into each respective column the right way?
i need to extend this so that i can inlcude another column from a different table. so let's say i have a colume in table Price and the column i want to display in datagrid header is cost, how can i do this? there is code backend but could i simply code the below to include this column?
Using formview or details view, I want to allow users to both input data into columns (I know how to do that) and add additional columns to the existing table if necessary.
I pivoted my gridview with this code. But This code is not mine. Just tested and worked. But i dont know how can i add remove/add buttons to all columns.
1. As per my knowledge we use dataadapters/dataset when we want to deal with the huge amount of column/data. Is there anyway that if I want to update one or two columns in a table without using dataadapter/dataset?
2. There is a way that without clicking a button we can get the data using objectdatasource, I mean to say that there is no vb.net data in the code behind then how to debug if there is not data in vb.net in code behind.
Iam working on an asp.net application.Recently client come with new requirement. Need a control which is similar to table or like gridview with rows and columns.It should allow user to enter data in the cells. And when the user press tab it should go to next cell and finally if we press enter key, it should validate the data entered in the current row and if data is correct it should create a new empty next row(like entering data manually in an sqlserver table). How can i implement this functionality? Can i use gridview / javascript to implement this functionality.
When adding a stored procedure into the Entity Data Model I can select whether the procedure returns a scalar, a (new) complex type or one of the entity types I already defined.I mean assuming I have a view like this
CREATE VIEW FilteredFoos as SELECT Foo.* FROM Foo join ... WHERE ...(that is a view that implements some involved filtering, but returns all columns from one table) how do I add it to the project so that I can use the entity set, but get the Foo objects, not some new FilteredFoo objects.
var foos = myDB.FilteredFoos.Include("Bar").ToList(); foreach (Foo foo in foos) { ...
I have a table in my database called "Profiles". This holds data on Female and Male personal characteristics.On my aspx, I have a formview in edit mode which is binded to an object data source with a GetDataByUserId Select methodwhich retrieves data from the "Profiles" Table via a DAL.The "Profiles" table has some columns which relates to females only and some just males and some are generic to both.See example below
UserId - / of Type GUID GenreId / of Type BOOL. Hip Size (For females) Dress Size ( For Females) ChestSize (For Men ) TrouserSize (For Men) Weight ( For both )
When the User logs in , they go to an update Page which has the Formview in Edit Item Mode and contains drop down Lists whichare binded to the Users Selected Value. The DDL are in turn bound to their related table such as HIP, Dress, Chest, Trouser etc.bjectiveIf a female user logs in I just want to show them the (Hip Size) DDL and DressSizeDDL in the Edit item template of the formview and not the ChestSize DDL or TrouserSize DDL.At present the GetProfileByUserId returns all colums from the tableMy question is how do I do this and just show DDL which are relevant to the Female or Male Only. In some cases the usermay not have selected an item in the previous form so they could also be NULL.Am i on the right path by writing a Select Query that checks to see if the User is Male or Female by checking the Genre column in Profiles first.Do I also need 2 panels, 1 to hide Female DDLS and the other to Hide MaleDDLs subject to logged in user genre.
I have to parse the data to dropdownlist and then choosed the data from dropdownlist, this data will be appear in listbox. But my problem is when I parse the data to dropdownlist, I used updatepanel. It is no problem. It is okay. And then when I choose the data from dropdownlist, It can't be appear in listbox. Why? I have no idea. My code is :
I'm creating a table in an asp.net code behind dynamically, and I want to have a footer row that only has 2 cells. The first should span all the columns in the table-1. Is there some way other then keeping track of the # of columns in the table manually for me to set the colspan to be # of all the columns in the table-1? Preferably a HTML or CSS solution?
I've the following code which successfully makes an average for all the columns from a table. What I need to do though is ignore certain columns in this equation.
Dim totalNumber as Double = 0 Dim count as Integer = 0 For x = 0 To xyz123.Tables(0).Columns.Count - 1 Dim current as Double = 0 If Double.TryParse(xyz123.Tables(0).Rows(0)(x).ToString(), current) AndAlso current <> 0 Then count += 1 totalNumber += current End If Next Dim averageRating as Double = totalNumber / count
I have the following data that basically I only need a few bits of information from:
Resource:X - Y;Z - Å;Type:(all) From Date: 07/12/2010 - To Date 07/12/2010 Sort by:Time Include Referring source/physician:No Footer:Default Criteria:None ","Appointments","X, Y","ZAssociates","Monday, July 12, 2010","Time","Patient Name","Patient ID","Appt. Type","Ref. Source/ Physician","Phone","Type","DOB ","Z, X","Y","7/12/2010 12:00:00AM","Time","Patient Name","Patient ID","Appt. Type","Phone","Type","DOB "," 7:30 [snip]
The only things I need from this are:
Patients Name Drs Name Patients Phone Number Appt Time Appt Date
and the rest of the information I can discard. A customer uploads this as a .csv file (even though it really isn't as you can see) and I'd like to parse the needed information and post that to my SQL database and discard the rest. I think I can do this with a dataset but I've never built that before. The fields from the customer will always be the same and the fields I will need will always be the same. Also, the date time has to be in the format of yyyy/mm/dd:hhmm and the phone number always has to have 512 as a prefix. Here is the code I currently have for my site:
Imports System.IO Imports System.Data Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub Submit1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim SaveLocation = "\xxxWEB3wwwrootWebfile1RemindersDoug_Ancildoug.csv" If UploadFile(SaveLocation) Then 'the file was uploaded: now try saving it to the database SaveToDatabase(SaveLocation) End If End Sub Private Function UploadFile(ByVal SavePath As String) As Boolean Dim fileWasUploaded As Boolean = False 'indicates whether or not the file was uploaded 'Checking if the file upload control contains a file If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then Try 'checking if it was .txt file BEFORE UPLOADING IT! 'You used to upload it first...but the file could be a virus If File1.FileName = ("doug.csv") = False Then 'The file is not the expected type...do not upload it 'just post the validation message message.Text = "Sorry, thats not the correct file." message2.Text = "Please locate and upload 'doug.csv'" Else 'The file is a .txt file 'checking to see if the file exists already 'If it does exist Deleting the existing one so that the new one can be created If IO.File.Exists(SavePath) Then IO.File.Delete(SavePath) End If 'Now upload the file (save it to your server) File1.PostedFile.SaveAs(SavePath) 'After saving it check to see if it exists If File.Exists(SavePath) Then 'Upload was sucessful message.Text = "Thank you for your submission." fileWasUploaded = True Else 'the file was not saved message.Text = "Unable to save the file." End If End If Catch Exc As Exception 'We encountered a problem message.Text = "Your file was not in the correct format. Please contact Customer Service at xxxx-xxxx-xxxx." End Try Else 'No file was selected for uploading message.Text = "Please select a file to upload." End If Return fileWasUploaded End Function Private Sub SaveToDatabase(ByVal SavePath As String) Try Dim sqlQueryText As String = _ "BULK INSERT dialerresults " + _ "FROM '" & SavePath & "' " + _ "WITH ( FIELDTERMINATOR = ',' , ROWTERMINATOR = ' ' )" ' and bulk import the data: 'If ConfigurationManager.ConnectionStrings("Dialerresults") IsNot Nothing Then 'Dim connection As String = ConfigurationManager.ConnectionStrings("Dialerresults").ConnectionString Dim connection As String = "data source=10.2.1.40;initial catalog=IVRDialer;uid=xxxx;password=xxxxx;" Using con As New SqlConnection(connection) con.Open() ' execute the bulk import Using cmd As New SqlCommand(sqlQueryText, con) cmd.ExecuteNonQuery() End Using End Using 'Else 'message.Text="ConfigurationManager.ConnectionStrings('Dialerresults') is Nothing!" 'End If Catch ex As Exception message.Text = "Your file was not in the correct format. Please contact Customer Service at xxxxxxx." End Try End Sub End Class
I'm looking to parse the cs(Referer) column in one of log files for the following data found intween the followingbolded URL parameters and was wondering what commands in a select statement would be the best way for doing this.[URL]Example - I would be able to parse the "2" found after "start=" and the data "castle%2bshore" inbetween "%3Fq%3D" and "%26"
I have a GridView that has several dynamic columns (I do not know how many at design time and it could be 0-12 columns, hence need for dynamic columns). I have the columns in the grid and data bound to them - works great. There are other standard, design-time TemplateField columns with TextBox controls in them. These are bound with values that the user can edit. The grid is posted back via a Submit button. My question is "Why does gv.Columns.Insert() cause all my TextBox data to be null on Postback, but gv.Columns.Add() works like a champ?"
protected void BuildColumns() { // The first column to begin to insert the columns in the GridView int columnIndex = 5; BoundField aoColumn = new BoundField(); aoColumn.HeaderText = "New Column 1"; gvMyGrid.Columns.Insert(columnIndex, aoColumn); // kills txtQuantity.Text on postback gvMyGrid.Columns.Add(aoColumn); // works fine columnIndex++; foreach (MyEntity my in _myEntityCollection) { BoundField myColumn = new BoundField(); myColumn.HeaderText = String.Format("{0:d}", my.StartDate); gvMyGrid.Columns.Insert(columnIndex, myColumn); columnIndex++; } }
I then go on to assign values to these BoundFields in the _RowDataBound method and all of this works great. However, when I post back and try to reference some TextBox and they are all null. And yes, I have the BuildColumns() call wrapped in if (!IsPostBack) on Page_Load. Of course I would like to use .Insert() so that the columns can go in the proper location and not at the end of the Columns array.
I created a gridview that is made up of 4 gridviews and using a stored procedure to populate it. I create columns at runtime because the number of columns changes all the time.To make the grids editable I am adding template fields at runtime as I create the columns, this is to ensure that a user is able to edit the cells and some foot values update. Reason why I have four grids is to freeze rows and columns like in excel using javascript. The problem is that performance is very bad especially in IE, the grids take a long time to load. I am not sure if this is caused by the data load or the creation of text boxes. see some of the code below for my _aspx page:
in asp.net page user able to select gridview Columns, and it will hide remaining columns and that selection done by check box with column list bellow is Image link , what exactly I am looking for [URL] it look bellow after selection of column done [URL]
i have a table that has some columns and rows i want this table to have borders that are visible inside it i want every column an row to be closed in borders how can i do that?
CS1061: 'System.Data.SqlClient.SqlDataAdapter' does not contain a definition for 'Rows' and no extension method 'Rows' accepting a first argument of type 'System.Data.SqlClient.SqlDataAdapter' could be found.
ive have a call that pulls back an RSS feed and displays it in a label but theres stuff i dont want after the word "Fast" how do i go about parsing a label field to stop displaying anything after the word "fast".... if that makes sense
P.S! this isnt my first post had to create a new account. microsoft! when you click forgot password it brings up an error...and the few times it works the link it sends you is expired when you click on it..been like that for 2 weeks!