Home > Net >  Winform database
Winform database

Time:09-21

I now put the database and winform interface is probably is ready, then the two are connected, that I am now on winform, that how to put the words and images to database?

CodePudding user response:

The thing to do too much, I will not answer, continue to downstairs,

CodePudding user response:

reference 1st floor wangmoxhn response:
this too much things to do, I will not answer, continue to downstairs,

Can say a little bit, or ideas

CodePudding user response:

Put the local image, record its relative diameter, text directly inserted into the line

CodePudding user response:

Write the SQL statements insert is, type, also have the image data in the database
No path way can also convert images to byte [] deposit

CodePudding user response:

Not to convert binary well before you can

CodePudding user response:

Generally speaking, the image should be saved to a path below, the database only keep its path,
But you must be saved to the database, it is recommended that you use VARBINARY (MAX), do not use the image. The image is a kind of abandoned format,

The following code pro measurement by:
 USE tempdb for 
GO
IF OBJECT_ID (' t ') IS NOT NULL
DROP TABLE t
GO
CREATE TABLE (t
Id INT IDENTITY (1, 1) PRIMARY KEY,
Img VARBINARY (MAX)
)
GO


 using System; 
Using System. The Data. SqlClient.
Using System. Drawing;
Using System. Drawing. Imaging;
using System.IO;

The namespace ConsoleApp3
{
Class Program
{
The static string connString=@ "Data Source=(local); Initial Catalog=tempdb for; Integrated Security=True ";
The static void Main (string [] args)
{
Try
{
String path="1. PNG";
Byte [] byteArr=File. ReadAllBytes (path);
String SQL="insert into t values (img) (@ img)";
Using (SqlConnection conn=new SqlConnection (connString))
{
Conn. The Open ();
SqlCommand CMD=new SqlCommand (SQL, conn);
CMD. The Parameters. AddWithValue (" @ img, "byteArr);
CMD. ExecuteNonQuery ();
}
Console. WriteLine (" Finished the Insert. ");

String this="select img from t where id=@ id";
Byte [] byteArrResult=null;
Using (SqlConnection conn=new SqlConnection (connString))
{
Conn. The Open ();
SqlCommand CMD=new SqlCommand (this, conn);
CMD. The Parameters. AddWithValue (" @ id ", 1);
ByteArrResult=CMD. ExecuteScalar () as byte [];
}
Path="1 _get. PNG";
SaveImgByByteArr (byteArrResult, path);
Console. WriteLine (" Finished the Get. ");
}
The catch (Exception ex)
{
Console. WriteLine (ex. Message);
}

The Console. The Read ();
}

///& lt; summary>
Save the file///
///& lt;/summary>
///& lt; Param name="byteArr & gt;"
///& lt; Param name="path" & gt;
Public static void SaveImgByByteArr (byte [] byteArr, string path)
{
Using (MemoryStream ms=new MemoryStream (byteArr))
{
Bitmap BMP=new Bitmap (ms);
BMP. Save (path, ImageFormat. Png);
}
}
}
}

CodePudding user response:

refer to the second floor qq_45737334 response:
Quote: refer to 1st floor wangmoxhn response:
this too much things to do, I will not answer, continue to downstairs,

Can say a little bit, or ideas

This is a permanent process, database construction, connections, insert data, do not have what to say

CodePudding user response:

Image video file, all the local big content have, little information (text, Numbers) is inserted in the database

CodePudding user response:

The images and files in binary form is the earliest I stored in the database, read and write in byte [] transformation;
Later local path into a database to store files or web links, of course if the files on the network, to form a complete set of upload and download function

CodePudding user response:

references 9/f, the magic of the octopus response:
is the earliest I put the pictures and files in binary form is stored in the database, read and write in byte [] transformation;
Later local path into a database to store files or web links, of course if the files on the network, but also supporting the upload and download function

As long as can be saved to a specified local folder

CodePudding user response:

reference 4 floor Bridge_go response:
is write SQL statements inserted, type, also have the image data in the database
No path way can also convert images to byte [] in the

Is there anyone to convert byte string appearing mistakes?

CodePudding user response:

references 9/f, the magic of the octopus response:
is the earliest I put the pictures and files in binary form is stored in the database, read and write in byte [] transformation;
Later local path into a database to store files or web links, of course if the files on the network, but also supporting the upload and download function

Is there anyone met byt convert a string of errors

CodePudding user response:

1, understand the input control similar input to access in the textbox, database matching the field type, 2, and understand the file access control, database corresponding to the field type, then consider the business logic,

CodePudding user response:

refer to 12th floor three-year-old son reply:
Quote: magical octopus, 9/f, reference response:
the images and files in binary form is the earliest I stored in the database, read and write in byte [] transformation;
Later local path into a database to store files or web links, of course if the files on the network, but also supporting the upload and download function

Is there anyone met byt conversion error string


Don't understand you?
I # 6 code didn't work for you?

CodePudding user response:

reference 14 floor gypsy song reply:
Quote: refer to 12th floor three-year-old son reply:

Quote: magical octopus, 9/f, reference response:
is the earliest I put the pictures and files in binary form is stored in the database, read and write in byte [] transformation;
Later local path into a database to store files or web links, of course if the files on the network, but also supporting the upload and download function

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related