|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
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?
|
|
|
|
|
Hello
I use IsDBNull a lot in my C# codes because I usually add Microsoft.Visualbasic reference to my CSharp codes. The full qualification is Microsoft.VisualBasic.Information.IsDBNull.
The way I use is below:-
<b>if (IsDBNull(MyDt.Rows[0]["StartDate"])) </b>
After retrieving my data into my datatable (MyDt), then I evaluate based on a column (startdate) of the datatable
You usually perform Isnumeric on variable in your code, but you perform IsDBNull on database field.
|
|
|
|
|
MessageBox.Show("New record has been added successfully!!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
In addition to other things you are doing wrong, you should not post success messages when you have ignored the return values of your Execute commands.
|
|
|
|
|
I agree need to know what line is throwing the error.
Can you see what ex.StackTrace shows in your Catch ex as Exception block?
Below lets you create a breakpoint when an error is raised then you can resume to the line giving the error
This is just to help you find your error line - use catch/try/end try otherwise
To debug remove your try, catch, end try then...
On Error GoTo err_handler
quit_proc:
Exit Function
err_handler:
MsgBox Error, vbCritical, CStr(Erl) + " " + CStr(Err)
Resume
|
|
|
|
|