|
The only advice I can gibe you is first to define what you want in a very detailed fashion.
- define how you want things to work in details.
- list functionalities you want.
...
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
sure thing. thanks man. i'll come back after doing that.
|
|
|
|
|
|
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
|
|
|
|