|
Jo_vb.net wrote: But I'm only on a better beginner level in coding... Lots of beginners here; most looking for templates to do their work.
Jo_vb.net wrote: could be used for a loop like the following: Don't worry about the big picture; understand the concept first, then you integrate it into your 'engine'.
Someone hit me if I wrong, but string s = File.ReadAllText(path, appendText, Encoding.UTF8); would load the data of that file into the string called s?
"xyz".Contains("c")
becomes
s.Contains("c")
Where s is then loaded from a file (specified in "path"). This way, the "xyz" isn't hardcoded, but just data in a file. Requires you to read a string from a file. Could you achieve that?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'm in doubt about this approach [the .Contains(s) method is only used in < 10% of the "if - then" statements/rules], but reading a text file line after line is possible.
|
|
|
|
|
The idea is not limited to that method
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi! Can somebody help me. I am beginner. I have a project and need to update datagridview with image column, using Access databse. I have code for insert new row with image and as I understand it can be modified for updating row. I try to modify, but problem is not working. Now no any alarms or errors occurs, database not changed.
Many thanks un advance.
<pre> Private Sub Btn_Save_Click(sender As Object, e As EventArgs) Handles Btn_Update.Click
Try
If PhotoPictureBox.Image Is Nothing Then
If MsgBox("Are you sure you don't want to upload any pictures?", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Missing picture") Then
Dim CN As New OleDbConnection(connection)
CN.Open()
Dim Int As String
Int = "UPDATE Germany set [Year_of_release]=@year_of_release, [Denomination]=@denomination, [Governing_body]=@governing_body, [Acquired]=@acquired, [Date_of_purchase]=@date_of_purchase, [Course]=@course, [Material]=@material WHERE [ID]=@ID"
Dim cmd As New OleDbCommand(Int, CN)
'cmd.Parameters.Add("@ID", OleDbType.VarChar).Value = IDTextBox.Text
cmd.Parameters.Add("@year_of_release", OleDbType.VarChar).Value = Year_of_releaseDateTimePicker.Value
cmd.Parameters.Add("@denomination", OleDbType.VarChar).Value = DenominationTextBox.Text
cmd.Parameters.Add("@governing_body", OleDbType.VarChar).Value = Governing_bodyTextBox.Text
cmd.Parameters.Add("@acquired", OleDbType.VarChar).Value = AcquiredTextBox.Text
cmd.Parameters.Add("@date_of_purchase", OleDbType.VarChar).Value = Date_of_purchaseDateTimePicker.Value
cmd.Parameters.Add("@course", OleDbType.VarChar).Value = CourseTextBox.Text
cmd.Parameters.Add("@material", OleDbType.VarChar).Value = MaterialTextBox.Text
cmd.ExecuteNonQuery()
cmd.Dispose()
CN.Close()
CN.Dispose()
End If
Else
If imgName <> "" Then
Dim fs As FileStream
fs = New FileStream(imgName, FileMode.Open, FileAccess.Read)
Dim picturebytes As Byte() = New Byte(fs.Length - 1) {}
fs.Read(picturebytes, 0, System.Convert.ToInt32(fs.Length))
fs.Close()
Dim CN As New OleDbConnection(connection)
CN.Open()
Dim Int As String
Int = "UPDATE Germany set [Year_of_release]=@year_of_release, [Denomination]=@denomination, [Governing_body]=@governing_body, [Acquired]=@acquired, [Date_of_purchase]=@date_of_purchase, [Course]=@course, [Material]=@material, [Photo]=@photo WHERE [ID]=@ID"
Dim imgparam As New OleDbParameter()
imgparam.OleDbType = OleDbType.Binary
imgparam.ParameterName = "@photo"
imgparam.Value = picturebytes
Dim cmd As New OleDbCommand(Int, CN)
cmd.Parameters.Clear()
cmd.Parameters.Add("@ID", OleDbType.VarChar).Value = IDTextBox.Text
cmd.Parameters.Add("@year_of_release", OleDbType.VarChar).Value = Year_of_releaseDateTimePicker.Value
cmd.Parameters.Add("@denomination", OleDbType.VarChar).Value = DenominationTextBox.Text
cmd.Parameters.Add("@governing_body", OleDbType.VarChar).Value = Governing_bodyTextBox.Text
cmd.Parameters.Add("@acquired", OleDbType.VarChar).Value = AcquiredTextBox.Text
cmd.Parameters.Add("@date_of_purchase", OleDbType.VarChar).Value = Date_of_purchaseDateTimePicker.Value
cmd.Parameters.Add("@course", OleDbType.VarChar).Value = CourseTextBox.Text
cmd.Parameters.Add("@material", OleDbType.VarChar).Value = MaterialTextBox.Text
cmd.Parameters.Add(imgparam)
cmd.ExecuteNonQuery()
cmd.Dispose()
CN.Close()
CN.Dispose()
End If
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
|
|
|
|
|
Please do not repost the same question.
|
|
|
|
|
Hi! Can somebody help me. I am beginner. I have a project and need to update datagridview with image column, using Access databse. I have code for insert new row with image and as I understand it can be modified for updating row. I try to modify, but problem is not working. Now no any alarms or errors occurs, database not changed.
Many thanks un advance.
Private Sub Btn_Save_Click(sender As Object, e As EventArgs) Handles Btn_Update.Click
Try
If PhotoPictureBox.Image Is Nothing Then
If MsgBox("Are you sure you don't want to upload any pictures?", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Missing picture") Then
Dim CN As New OleDbConnection(connection)
CN.Open()
Dim Int As String
Int = "UPDATE Germany set [Year_of_release]=@year_of_release, [Denomination]=@denomination, [Governing_body]=@governing_body, [Acquired]=@acquired, [Date_of_purchase]=@date_of_purchase, [Course]=@course, [Material]=@material WHERE [ID]=@ID"
Dim cmd As New OleDbCommand(Int, CN)
'cmd.Parameters.Add("@ID", OleDbType.VarChar).Value = IDTextBox.Text
cmd.Parameters.Add("@year_of_release", OleDbType.VarChar).Value = Year_of_releaseDateTimePicker.Value
cmd.Parameters.Add("@denomination", OleDbType.VarChar).Value = DenominationTextBox.Text
cmd.Parameters.Add("@governing_body", OleDbType.VarChar).Value = Governing_bodyTextBox.Text
cmd.Parameters.Add("@acquired", OleDbType.VarChar).Value = AcquiredTextBox.Text
cmd.Parameters.Add("@date_of_purchase", OleDbType.VarChar).Value = Date_of_purchaseDateTimePicker.Value
cmd.Parameters.Add("@course", OleDbType.VarChar).Value = CourseTextBox.Text
cmd.Parameters.Add("@material", OleDbType.VarChar).Value = MaterialTextBox.Text
cmd.ExecuteNonQuery()
cmd.Dispose()
CN.Close()
CN.Dispose()
End If
Else
If imgName <> "" Then
Dim fs As FileStream
fs = New FileStream(imgName, FileMode.Open, FileAccess.Read)
Dim picturebytes As Byte() = New Byte(fs.Length - 1) {}
fs.Read(picturebytes, 0, System.Convert.ToInt32(fs.Length))
fs.Close()
Dim CN As New OleDbConnection(connection)
CN.Open()
Dim Int As String
Int = "UPDATE Germany set [Year_of_release]=@year_of_release, [Denomination]=@denomination, [Governing_body]=@governing_body, [Acquired]=@acquired, [Date_of_purchase]=@date_of_purchase, [Course]=@course, [Material]=@material, [Photo]=@photo WHERE [ID]=@ID"
Dim imgparam As New OleDbParameter()
imgparam.OleDbType = OleDbType.Binary
imgparam.ParameterName = "@photo"
imgparam.Value = picturebytes
Dim cmd As New OleDbCommand(Int, CN)
cmd.Parameters.Clear()
cmd.Parameters.Add("@ID", OleDbType.VarChar).Value = IDTextBox.Text
cmd.Parameters.Add("@year_of_release", OleDbType.VarChar).Value = Year_of_releaseDateTimePicker.Value
cmd.Parameters.Add("@denomination", OleDbType.VarChar).Value = DenominationTextBox.Text
cmd.Parameters.Add("@governing_body", OleDbType.VarChar).Value = Governing_bodyTextBox.Text
cmd.Parameters.Add("@acquired", OleDbType.VarChar).Value = AcquiredTextBox.Text
cmd.Parameters.Add("@date_of_purchase", OleDbType.VarChar).Value = Date_of_purchaseDateTimePicker.Value
cmd.Parameters.Add("@course", OleDbType.VarChar).Value = CourseTextBox.Text
cmd.Parameters.Add("@material", OleDbType.VarChar).Value = MaterialTextBox.Text
cmd.Parameters.Add(imgparam)
cmd.ExecuteNonQuery()
cmd.Dispose()
CN.Close()
CN.Dispose()
End If
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
|
|
|
|
|
If you're not getting any errors, but your database is not being modified, then either there is no record in your database with the specified ID , or you're updating the wrong database.
One common problem is having a copy of your Access database as part of your project, and setting it to copy that file to the output directory. This will overwrite any changes you have made whilst your application was running.
You need to debug your code - in particular, check the value returned from the ExecuteNonQuery method, which will tell you the number of rows which were affected. In this case, it should return 1 - anything else indicates a problem with your data or your @ID parameter.
Quote:
Dim fs As FileStream
fs = New FileStream(imgName, FileMode.Open, FileAccess.Read)
Dim picturebytes As Byte() = New Byte(fs.Length - 1) {}
fs.Read(picturebytes, 0, System.Convert.ToInt32(fs.Length))
fs.Close() You can simplify that block to a single line:
Dim picturebytes As Byte() = File.ReadAllBytes(imgName)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi
Again I found info that uses an xml file to makes controls.
TaskbarItemInfo Class (System.Windows.Shell) | Microsoft Docs
However where do i put these files? How do I create them? add > file > xml and change the text. I can do that but how to completly implement those files?
I'm working with default windows vb.net applications
Jan
|
|
|
|
|
That is XAML code, which is used to create the visual parts of WPF applications.
|
|
|
|
|
If by "default", you mean a Windows Forms application, the code you found will not work. That is XAML code, which is used in WPF applications and controls.
|
|
|
|
|
Yes I did mean Windows Form Application
So When I see code like that I can create controls like described in de xaml and take over the code and adapt where needed?
Any advances for windows forms over wpf? in any direction? Found already this Difference between WPF and WinForms - GeeksforGeeks
Jan
|
|
|
|
|
As we have said, this is XAML code and will only work with WPF applications.
|
|
|
|
|
You cannot adapt that code to work in Windows Forms, at all.
If there any benefit to using Windows Forms over WPF? Sure, the learning curve for Windows Forms is much easier compared to WPF. The advantage WPF has over Windows Forms is incredible power to create a UI over what is possible in Windows Forms.
|
|
|
|
|
|
how to make .OBJ 3D model viewer for vb.net 2010
|
|
|
|
|
Get this: GitHub - 5everin/3D-Model-Viewer: A software renderer written in vb.net[^] ... and see if it won't open without an error usg VS2010 (as you suggest) ... but regardless of whether it loads or not, dissecting the classes just to have a look at how something apparently more modern in it's approach to .obj manipulation and viewing could prove informative enough for you to have a go at it yourself ... starting with a VS2010 project, scratchwise.
|
|
|
|
|
|
how to view obj with direct x 8 vb6
|
|
|
|
|
You might be better off choosing a development platform that's not extinct like the dodo bird.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
I'm not sure what you expect, you are asking for support for a language that has not been supported for more than 20 years!
I know some of us are fossils but you need to understand that memory becomes a problem for the aged (ancient)!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
|
Hi VB Experts,
I cannot update my data in the Excel and receive this error
Operator '=' is not defined for type for 'DBNull' and string '1'. The following is my codes:
Dim cnn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + str_Database + ";Extended Properties=Excel 12.0;")
Dim cmd = New OleDbCommand()
Dim str_SQL As String = ""
Dim int_Max_SN As Integer
Try
If (tb_SN.Text = "") Then
cnn.Open()
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT IIF(ISNULL(MAX(VAL([S/N]))), 0, MAX(VAL([S/N]))) FROM [Sheet2$]"
int_Max_SN = cmd.ExecuteScalar()
cnn.Close()
tb_SN.Text = int_Max_SN + 1
str_SQL += "INSERT INTO [Sheet2$] "
str_SQL += "([S/N], [MPN], [Description], [OEM (Manufacturer)], [MTBF (Hours)], [Failure Rate], [Repair Turn Around Time], [Utilization Rate], [Population], [Spares Required], [Testing], [Price Per Unit], [Total Cost Per Line Item]) "
str_SQL += "VALUES (" + tb_SN.Text + ", "
str_SQL += "'" + tb_MPN.Text + "', "
str_SQL += "'" + tb_Description.Text + "', "
str_SQL += "'" + tb_OEM.Text + "', "
If (IsNumeric(tb_MTBF.Text)) Then str_SQL += tb_MTBF.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Failure_Rate.Text)) Then str_SQL += tb_Failure_Rate.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Year_Of_Support.Text)) Then str_SQL += tb_Year_Of_Support.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Utilization_Rate.Text)) Then str_SQL += tb_Utilization_Rate.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Population.Text)) Then str_SQL += tb_Population.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Spares_Required.Text)) Then str_SQL += tb_Spares_Required.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Price_Per_Unit.Text)) Then str_SQL += tb_Price_Per_Unit.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Total_Cost_Per_Line_Item.Text)) Then str_SQL += tb_Total_Cost_Per_Line_Item.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Total_Uptime.Text)) Then str_SQL += tb_Total_Uptime.Text Else str_SQL += "null "
str_SQL += ")"
cnn.Open()
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = str_SQL
cmd.ExecuteNonQuery()
cnn.Close()
LoadRecords()
MessageBox.Show("New record has been added successfully!!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
For int_Row_Index As Integer = 0 To dgv_Excel.Rows.Count - 1
If (dgv_Excel.Rows(int_Row_Index).Cells(0).Value = tb_SN.Text) Then
dgv_Excel.Rows(int_Row_Index).Cells(1).Value = tb_MPN.Text
dgv_Excel.Rows(int_Row_Index).Cells(2).Value = tb_Description.Text
dgv_Excel.Rows(int_Row_Index).Cells(3).Value = tb_OEM.Text
dgv_Excel.Rows(int_Row_Index).Cells(4).Value = IIf(IsNumeric(tb_MTBF.Text), tb_MTBF.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(5).Value = IIf(IsNumeric(tb_Failure_Rate.Text), tb_Failure_Rate.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(6).Value = IIf(IsNumeric(tb_Year_Of_Support.Text), tb_Year_Of_Support.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(7).Value = IIf(IsNumeric(tb_Utilization_Rate.Text), tb_Utilization_Rate.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(8).Value = IIf(IsNumeric(tb_Population.Text), tb_Population.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(9).Value = IIf(IsNumeric(tb_Spares_Required.Text), tb_Spares_Required.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(10).Value = IIf(IsNumeric(tb_Price_Per_Unit.Text), tb_Price_Per_Unit.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(11).Value = IIf(IsNumeric(tb_Total_Cost_Per_Line_Item.Text), tb_Total_Cost_Per_Line_Item.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(12).Value = IIf(IsNumeric(tb_Total_Uptime.Text), tb_Total_Uptime.Text, DBNull.Value)
int_Row_Index += 1
End If
Next
str_SQL += "UPDATE [Sheet2$] "
str_SQL += "SET [MPN] = '" + tb_MPN.Text + "', "
str_SQL += "[Description] = '" + tb_Description.Text + "', "
str_SQL += "[OEM (Manufacturer)] = '" + tb_OEM.Text + "', "
If (IsNumeric(tb_MTBF.Text)) Then str_SQL += "[MTBF (Hours)] = " + tb_MTBF.Text + ", " Else str_SQL += "[MTBF (Hours)] = null, "
If (IsNumeric(tb_Failure_Rate.Text)) Then str_SQL += "[Failure Rate] = " + tb_Failure_Rate.Text + ", " Else str_SQL += "[Failure Rate] = null, "
If (IsNumeric(tb_Year_Of_Support.Text)) Then str_SQL += "[Repair Turn Around Time] = " + tb_Year_Of_Support.Text + ", " Else str_SQL += "[Repair Turn Around Time] = null, "
If (IsNumeric(tb_Utilization_Rate.Text)) Then str_SQL += "[Utilization Rate] = " + tb_Utilization_Rate.Text + ", " Else str_SQL += "[Utilization Rate] = null, "
If (IsNumeric(tb_Population.Text)) Then str_SQL += "[Population] = " + tb_Population.Text + ", " Else str_SQL += "[Population] = null, "
If (IsNumeric(tb_Spares_Required.Text)) Then str_SQL += "[Spares Required] = " + tb_Spares_Required.Text + ", " Else str_SQL += "[Spares Required] = null, "
If (IsNumeric(tb_Price_Per_Unit.Text)) Then str_SQL += "[Testing] = " + tb_Price_Per_Unit.Text + ", " Else str_SQL += "[Testing] = null, "
If (IsNumeric(tb_Total_Cost_Per_Line_Item.Text)) Then str_SQL += "[Price Per Unit] = " + tb_Total_Cost_Per_Line_Item.Text + ", " Else str_SQL += "[Price Per Unit] = null, "
If (IsNumeric(tb_Total_Uptime.Text)) Then str_SQL += "[Total Cost Per Line Item] = " + tb_Total_Uptime.Text + " " Else str_SQL += "[Total Cost Per Line Item] = null "
str_SQL += "WHERE VAL([S/N]) = " + tb_SN.Text
cnn.Open()
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = str_SQL
cmd.ExecuteNonQuery()
cnn.Close()
MessageBox.Show("Record has been updated successfully!!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
modified 21-Apr-22 11:15am.
|
|
|
|
|
|
Which line is generating that error?
|
|
|
|
|