|
In an existing vb.net 2010 app, I am getting the following error message when I debug the code and use a sql server database:
System.ArgumentException {"Keyword not supported;'testdb; database'."}
The error message come from the following code:
#Region "Public Shared Function OpenConnectionO() As SqlConnection"
Public Shared Function OpenConnectionA() As SqlConnection
Dim con As SqlConnection = New SqlConnection(SiteHelper.SQLConnectionStringO)
con.Open()
Return con
End Function
#End Region
This is code that has existed for a very long time. What is new is the connection is being made to a new test database that has been setup within the last 6 months.
The config file looks like the following:
<connectionStrings>
<clear />
<add name="sqlO" connectionString="TestI; Database=OPS; User ID=Usr; Password=etxxxxxx;" />
</connectionStrings>
Thus would you tell me what you suggest I try so that I can determine where the error lies?
|
|
|
|
|
Can you post the stacktrace?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Please show the actual text of the string being used in that command.
|
|
|
|
|
|
found answer. You are correct that this is not a valid connection string. I change the string and this solved the problem.
|
|
|
|
|
invalid connection string was the problem
|
|
|
|
|
Dim timediff As String = ((hr.ToString("00") & ":") + min.ToString("00") & ":") + sec.ToString("00")
|
|
|
|
|
What do you mean? Try showing the result you have versus the result you would like to have.
|
|
|
|
|
the result of 8:45 am to 11:06 am is 2hrs and 21 mins but it gives me an answer of 23.
|
|
|
|
|
OK, so show the code that's doing the calculation because the code you already posted isn't it.
|
|
|
|
|
Dim sDateFrom As String
Dim sDateTo As String
sDateFrom = CStr(row.Cells(3).FormattedValue)
sDateTo = CStr(row.Cells(4).FormattedValue)
If DateTime.TryParse(sDateFrom, dfrom) AndAlso DateTime.TryParse(sDateTo, dto) Then
tHrs = dto - dfrom
Dim hr As Integer = tHrs.Hours
Dim min As Integer = tHrs.Minutes
Dim sec As Integer = tHrs.Seconds
Dim timediff As String = ((hr.ToString("00") & ":") + min.ToString("00") & ":") + sec.ToString("00")
|
|
|
|
|
Try formatting the timespan, instead of each item.
|
|
|
|
|
Ummm.... you're getting the formatted date/times from two grid cells, converting them to strings, them parsing those strings back into what I am assuming are two DateTime fields, dto and dfrom, doing some math on them and then... yeah, this is a freakin' mess.
If you're doing this properly, you don't need all this stuff. All you need is the Values of those Cells, not the formatted values. But, then again, I'm assuming your database is storing dates and times as Date/Time and not strings. You BETTER be storing these things as the correct types otherwise you're really making your life much harder than it needs to be.
dto = row.Cells(3).Value
dFrom = row.Cells(4).Value
result = dto - dfrom
Console.WriteLine("{0}", result))
|
|
|
|
|
It's the new paradigm - convert DateTimes to Strings so you can convert them back to DateTimes:
I came across a similar issue earlier today in the C# forum.
|
|
|
|
|
i need vb.net code. because i used Visual Studio .net thanks
|
|
|
|
|
The code Dave posted is VB.NET code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That is because your code is wrong, the following C# sample gives the correct answer:
DateTime start = new DateTime(2016, 3, 14, 8, 45, 0);
DateTime end = new DateTime(2016, 3, 14, 11, 6, 0);
TimeSpan diff = end - start;
Console.WriteLine("TimeSpan is {0} hours and {1} minutes", diff.Hours, diff.Minutes);
However, since you did not show us the code we have no idea why it is wrong.
|
|
|
|
|
Like this;
namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
DateTime date1 = new DateTime(year: 2491, month: 5, day: 1, hour: 0, minute: 0, second: 5);
DateTime date2 = new DateTime(year: 2491, month: 5, day: 1, hour: 17, minute: 15, second: 3);
TimeSpan ts = date1 - date2;
Console.WriteLine(ts.ToString());
Console.WriteLine(string.Format("The bomb will explode in {0:%h} hours, {0:%m} minutes and {0:%s} seconds.", ts));
Console.ReadKey();
}
}
}
..but then in VB, right?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The VB version is much simpler:
Console.WriteLine("The bomb will explode now.")
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Whehe
|
|
|
|
|
Hello
I am programming with vb.net and mysql database, and I have a database 'boky' and 3 tables, (table hard : id_hard,name, ip, id_user) , (table os: id-os, libelle), (table user: id_user, name, mailuser).
if I insert data in table hard, there is an error message ("cannot add or update a child row: a foreign key constraint fails ('boky'.'hard', CONSTRAINT 'FK_hard_id_user' FOREING KEY ('id_user') REFERENCES 'user' (id_user))"
this is my source code
Dim query As String = "INSERT INTO hard(name, ip, id_user) VALUES (?,?,?)"
Dim query 2 As String = "SELECT @@Identity"
Dim connstring As String = "server=localhost;UID=Dohery;Database=boky;Password=122346"
Dim Id As Integer
Using conn As New MySqlConnection (connstring)
Using cmd As New MySqlCommand(query,conn)
cmd.Parameters.AddWithValue("",TextBox11.Text)
cmd.Parameters.AddWithValue("",TextBox9.Text)
cmd.Parameters.AddWithValue("",ComboBox6.Text)
conn.Open()
cmd.ExecuteQuery()
cmd.CommandText = query2
ID=cmd.ExecuteScalar()
End Using
End Using
Help me plezzzzzz, thanks.
modified 14-Mar-16 3:16am.
|
|
|
|
|
The database is looking for a User_ID in your user table.
You need to make sure the User_ID exists in the user table BEFORE you insert the hard record.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The bright side - it's Friday
I have a datagridview that is databound with a bindingsource to a strongly typed dataset. There are 5 columns: 2 text fields, 2 combos (that have a datarelation to child tables) and a checkbox.
If I click to add a new row and manually type\select values - every thing works as expected. Meaning, as I am filling in data, there is another blank row below that is added. To help streamline data entry, I want to specify default values for the fields.
If I attempt to default values via dgv_DefaultValuesNeeded or the bs.AddingNew: All the default values are displayed correctly - but a new blank row isn't added to the end of the datagridview.
The last visible row (has all values defaulted correctly) but there isn't a blank line below? If I double click a combobox (don't even change the value - just double click it) or click the checkbox, then the change is reflected properly to the bindingsource and a new black line is added below?
I'm not sure what is going on. The comboboxes are set properly because the DisplayMember values are correct. If I click a previous row (without clicking the checkbox or selecting a combobox) the new row is removed as well - which makes it seem like it's not actually being added to the bindingsource during the AddingNew event.
Very stumped on this. Curious if anyone else has run into this. Probably missing something overly simple.
Private Sub bsPlantLocSub_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles bsPlantLocSub.AddingNew
Dim strTemp As String = GetNewDefaultValue_LabelPrefix()
dsLocSetup.DataTable_PlantLocSub.PlantLocationIDColumn.DefaultValue = _Default_PlantLocID
dsLocSetup.DataTable_PlantLocSub.LabelPrefixColumn.DefaultValue = strTemp
dsLocSetup.DataTable_PlantLocSub.LocationSubColumn.DefaultValue = "Location:" & Strings.Right(strTemp, 4)
dsLocSetup.DataTable_PlantLocSub.ComponentStatusColumn.DefaultValue = "IC"
dsLocSetup.DataTable_PlantLocSub.SysLocOnlyColumn.DefaultValue = False
bsPlantLocSub.MoveLast()
End Sub
I had also tried this in the bs.AddingNew - same behavior as listed above.
Dim dv As DataView = TryCast(bsPlantLocSub.List, DataView)
Dim drv As DataRowView = dv.AddNew
Dim strTemp As String = GetNewDefaultValue_LabelPrefix()
drv("PlantLocationID") = _Default_PlantLocID
drv("LabelPrefix") = strTemp
drv("LocationSub") = "Location:" & Strings.Right(strTemp, 4)
drv("ComponentStatus") = "IC"
drv("SysLocOnly") = False
e.NewObject = drv
bsPlantLocSub.MoveLast()
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I could lookup the DataGridView on MSDN and check, but in this case I am wondering whether you know what to expect from the default behaviour.
Jon_Boy wrote: The last visible row (has all values defaulted correctly) but there isn't a
blank line below? The new row with default-values is what you wanted, not an empty row. Make changes in that row and save it.
Jon_Boy wrote: but a new blank row isn't added to the end of the datagridview. An extra blank row would make the ones with the default values redundant. Overwrite any values you want there and save.
Jon_Boy wrote: If I double click a combobox (don't even change the value - just double click
it) or click the checkbox, then the change is reflected properly to the
bindingsource and a new black line is added below? Means you edited the row, and by changing focus it will be updating the bindingsource.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hey Eddy,
If all columns have defaulted values, wouldn't simply pressing tab on that row cause the new (blank) row to be added below? Why would a combo need to be selected or a text field need to go into edit mode to force the new row?
I tried to force a cell into edit mode after defaultvaluesneeded, but it causes a re-entrant condition, so the users is forced to do this.
Not a huge deal, but am a little confused when all the values are present.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|