I have a table in Access with 3 fields Key (autonumber), Field1 (Text), LookUp1 (combobox).The combobox field is working off a list that I manually entered into it (there are only three options Opt1, Opt2, Opt3..When I import the datagridview control, the fields all come across as Text, and I lose that combobox option.Can someone tell me how I can maintain the format of the fields within Access when I import? [code]
I have a simple VB program that is using the IBM ADO .NET data provider. I've set this up so the data is used by a data adapter and fed with a standard DS. I've manually done the commands to acheive this in code. I tthen use the DS as the datasource for my datagridview. I'm having one issue and that is with a date field. It uses an "old" IBM date of CYYMMDD, century, month, day date in a numeric field. So my dates look like this for instance in the datagridview:
1100804
My question is this, is there any easy way to format them into mm/dd/yy after the DS has been put into datagridview but not yet displayed?
I have done this using the dataread object and can work out a format that way, but I'd have to recode what I already have done.
Some code:
' use the command & connection to fill the data adapter adpt.SelectCommand = New iDB2Command(cmdText, Db2ConnectOSLD1F3) ' fill the tabel adapter
In my VB project I am returning an SQL datetime field to a date variable mdtCreated = CType(oReader("dtCreated"), Date) In an example it returns mdtCreated as #5/13/2011 2:59:43 PM# which is correct. Later on I want to show this as a string to dd/mm/yyyy format. I have tried mdtCreated.ToString("dd/mm/yyyy hh:mm:ss") But that returns "13/59/2011 02:59:43". I want it to return "13/05/2011 14:59:43" How can I achieve this?
I'm trying to format a datetime field to just show the date. The datetime is bound to an asp:label and for the Text attribute I have tried the following....
In all cases I get a green wavy line under the equation and the tip help says "Validation (ASP.Net): If this attribute value is enclosed in quotation marks, the quotation marks must match. String.Format("{0:D}", DateTime.Now) is the syntax that I have been told should work.
I am trying to format a string of arbitrary length into a fixed width field for display.
Let's use a width of 20 as an example, and call the string to be formatted s. I'm adding the formatted string to a StringBuilder named b.
Dim b As New System.Text.StringBuilder() Dim s as New String
If the string I want to display is shorter than 20 characters, I can do this:
b.Append(s.PadRight(20))
or
b.AppendFormat("{0,-20}", s)
So far, so good. But, if the string is longer than 20 characters, I want the string to be truncated to 20 characters as it is appended. The code above appends the entire string.
I tried this:
b.Append(s.Substring(0,20).PadRight(20))
But, this fires an exception if the string was shorter than 20 characters.
So, I ended up with:
b.Append(s.PadRight(20).Substring(0,20))
This seems to do the job. The PadRight prevents the exception by making sure thet string has 20 characters before the Substring is performed.
I was wondering if there is an alternate method that would look more elegant and avoid padding the string just so prevent the substring from causing an exception. Have I missed a feature of String.Format that can accomplish this in one step?
Edited to add solution:
I ended up with the following code:
Module Extensions <Extension()> _ Function AppendFixed(ByVal b As StringBuilder, ByVal s As String, ByVal width As Integer) As StringBuilder
[Code]....
This uses an extension method to clean up the syntax, as suggested by Joel and Merlyn, and uses the StringBulider Append overloads to avoid creating new strings that will have to be garbage collected, as suggested by supercat.
I'm simply databinding the data (containing date values) I got with a DataReader as in the following code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim id As Integer = Request.QueryString("id") 'Start connection
I have a textbox pulling an 'entryDate' field from my table using databinding. The field in the database is set to a 'Short Date', however when I bind that field to a text box and run the app it appends "12:00 AM" to the short date from the Db.
How do I get my databound textbox to simply display the short date which exists in the table?
I am a bit new to crystal reports even though I've been doing a bit of heavy lifting with it.I have this crystal report that has a datetime field.This field has a default datetime of 1753-01-01 00:00. Now I want this field to display only date like "01-03-2011" and also anywhere it sees the default date, it should display an empty string like To achieve this I used this formular (in the display string)
if CurrentFieldValue = DateValue('1753-01-01 00:00:00') then '' else totext(CurrentFieldValue)
This successfully changes the default date to empty string. But now I can no longer change the format to dates only.
I need to create a program that when it is opened, Focus will be always in that program until someone with any way will close it. I've tried to add Me.GetFocus() in the LostFocus event but nothing happens, I've tried to add Me.activate() when the Deactivate() event raises and when I debugged the program worked but when I run the biulded .exe file nothing happens again! how I can manage this Function?
I want to know that is it possible to convert exe file(made from vb2008) to vb source code..if it is possible then how can i maintain Privacy of my program.
I have a string variable called str assigned with "John". I changed it to "Dave" when the first button is clicked. When the second is clicked, I displayed the value to a label. I wanna see Dave but I just see John. Why is that?
There is nothing on page load and nothing else where. I know I can put into a session but this is on the same page. Can I not do without session or viewstate. [code]...
i just want to know how to maintain the position of an object w.r.t the window in vb when i resize the window during run-time.i tried anchoring it from all sides and the object resizes along with it.
I was wondering if there is a way to keep the same scroll position in a datagrid view as the app jumps around to various rows (driven by the user selecting different timestamps or address). After the jump happens, the horizontal slider moves all the way to the right, but I want it at the same position as before the jump (or at lease go all the way to the left).
I have tried numerous things (datatable.AcceptChanges(), etc) but haven't been able to figure it out yet.
Datatable contain some values like 0.0,10000.00,54678.94. I am getting that values using for loop and store it in a variable in double datatype. I want to add these nos and store it in a variable. Each time variable value changed.
for loop Dim ds5 As dataset1.pro_dtsumDataTable = TA5.GetData(TextBox1.Text, users) If (ds5.Rows.Count > 0) Then Dim y As Double y = Double.Parse(ds5(0)("sum(fld_primary)").ToString()) Dim y1 As Double y1 = 0 + y End If Next
First time y1=0.0 Next time the value of y1 is not added to previous value. I want the result y1=64679.34
I need to launch a mainframe login screen from a shortcut so that the target and start in paths are preserved.
Before I figured out that the 'target' and 'start in' paths were problematic I was calling the .exe from the server using the following code and then sending keystrokes to the mainframe login dialog:
Private Sub btnDB1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDB1.Click Dim ProcID As Integer
[Code]...
...To launch the app from the shortcut, which works but I then can't call the process ID to set focus and send keystrokes to the login form.
I need a function in global.asax file which gets called only once when user enter a page url. application_beginrequest gets called 50-60 times in a single page( as to render a page several requests go to server.)
i though of a solution - I can write my fucntion in global.asax and call it on page load of other pages but in that solution I need to call it in every page. I would prefer something which is to be done only in global.asax
I would like to maintain a list of all of the strings entered into a ComboBox across all uses of an application on a given PC, for use as the AutoCompleteSource for that ComboBox, i.e., I enter in "Fred" in the ComboBox, commit the data, close the application, reopen the application, reopen the ComboBox, type "F", receive the suggestion "Fred".Assuming I already have in place code to create and maintain such a list in memory and add new elements to it as they are entered into the ComboBox, etc., what do you suggest as the best way to save/load this data in between sessions?Possible complicating factors: This application will be deployed via OneClick deployment, and will search for updates online every time the application starts. I would prefer that if the application updates, the list still exists after the update has completed.
I am using Visaul Studio 2010 to build a Windows Forms application to maintain a table in an SQL Server 2008 database. The table is named CASHBOOK and here are the further details:
I have the need to maintain a 4:3 aspect ratio on a Video control on a form. The forms (there could be up to 16 in a 4x4 layout) should all maintain a 4:3 aspect ratio when resized depending on clients monitor/resolution. The forms have a border and will keep them. The control is set to fill the form and is the only control on the form. Here is code that I use to create the initial layout:
I am developing FX software where Ticks are coming through socket and loading in listbox. but if i scroll down to see items its send back to me at top when new item add in listbox so what is way that scroll bar posstion remain at same where client want and its also keep add..
Public Function MethodOne(ByVal s As String) As String[code]...
I want to retain the value of i, but once it goes back into MethodOne, it loses its value. I tried making it static i As integer = 0, but this did not work.
I want to take the following result with the help of query in Crystal Reports:I have a stock table where three column's "type", "product", and "quantity" now I want that to drag two sql expressions in my report 1st is "INN" and 2nd is "Out" and it comes like if the "type" is purchase so it check the "product" field and ADD the quantity and if the type is Sale it less the quantity according to "product" So what query should I write to get the result?