C# 파일을 읽고 데이터베이스에 바이너리로 저장

2015 단어 C#

 
private void Save2DB(byte[] vbyte)
        {

            //         
            string AccPwd = "nsc";
            //         
            OleDbConnection myConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\RibbonGlobe\\bin\\Data\\modelData.mdb;Jet OLEDB:Database PassWord=" + AccPwd);
            myConnection.Open();


            string Sql_insert = "insert into ModelSourceList (Model_ID,Model_Name,Model_Attribute,Model_Data) values (@Model_ID ,@Model_Name, @Model_Attribute, @meshbuffer)";
            OleDbCommand myCommand = new OleDbCommand(Sql_insert, myConnection);
            try
            {
                //       
                //    
                OleDbParameter[] param = new OleDbParameter[4];
                param[0] = new OleDbParameter("@Model_ID", OleDbType.VarChar);
                param[0].Value = '1';
                myCommand.Parameters.Add(param[0]);

                param[1] = new OleDbParameter("@Model_Name", OleDbType.VarChar);
                param[1].Value = '1';
                myCommand.Parameters.Add(param[1]);

                param[2] = new OleDbParameter("@Model_Attribute", OleDbType.VarChar);
                param[2].Value = '1';
                myCommand.Parameters.Add(param[2]);

                param[3] = new OleDbParameter("@byteColumn", OleDbType.Binary, vbyte.Length);
                param[3].Value = vbyte;
                myCommand.Parameters.Add(param[3]);
                //       
                int resultUp0 = myCommand.ExecuteNonQuery();
                if (resultUp0 == 1)
                    MessageBox.Show("    !");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                //     fs.Close();
                myConnection.Close();
            }

        }

 

좋은 웹페이지 즐겨찾기