當前位置:首頁 » 編程語言 » sqlserver二進制

sqlserver二進制

發布時間: 2022-07-18 03:48:42

1. sqlServer存儲二進制圖片用什麼類型

存儲圖片:以二進制的形式存儲圖片時,要把資料庫中的欄位設置為Image數據類型(SQL Server),存儲的數據是Byte[]

2. sqlserver的數據類型

sqlserver的數據類型比較多,常用的包括:
第一大類:整數數據
bit:bit數據類型代表0,1或NULL,就是表示true,false.佔用1byte.
int:以4個位元組來存儲正負數.可存儲范圍為:-2^31至2^31-1.
smallint:以2個位元組來存儲正負數.存儲范圍為:-2^15至2^15-1
tinyint: 是最小的整數類型,僅用1位元組,范圍:0至此^8-1
第二大類:精確數值數據
numeric:表示的數字可以達到38位,存儲數據時所用的位元組數目會隨著使用權用位數的多少變化.
decimal:和numeric差不多
第三大類:近似浮點數值數據
float:用8個位元組來存儲數據.最多可為53位.范圍為:-1.79E+308至1.79E+308.
real:位數為24,用4個位元組,數字范圍:-3.04E+38至3.04E+38
第四大類:日期時間數據
datatime:表示時間范圍可以表示從1753/1/1至9999/12/31,時間可以表示到3.33/1000秒.使用8個位元組.
smalldatetime:表示時間范圍可以表示從1900/1/1至2079/12/31.使用4個位元組.
第五大類:字元串數據
char:長度是設定的,最短為1位元組,最長為8000個位元組.不足的長度會用空白補上.
varchar:長度也是設定的,最短為1位元組,最長為8000個位元組,尾部的空白會去掉.
text:長寬也是設定的,最長可以存放2G的數據.
第六大類:Unincode字元串數據
nchar:長度是設定的,最短為1位元組,最長為4000個位元組.不足的長度會用空白補上.儲存一個字元需要2個位元組.
nvarchar:長度是設定的,最短為1位元組,最長為4000個位元組.尾部的空白會去掉.儲存一個字元需要2個位元組.
ntext:長度是設定的,最短為1位元組,最長為2G.尾部的空白會去掉,儲存一個字元需要2個位元組.
第七大類:貨幣數據類型
money:記錄金額范圍為:-92233720368577.5808至92233720368577.5807.需要8 個位元組.
smallmoney:記錄金額范圍為:-214748.3648至214748.36487.需要4個位元組.
第八大類:標記數據
timestamp:該數據類型在每一個表中是唯一的!當表中的一個記錄更改時,該記錄的timestamp欄位會自動更新.
uniqueidentifier:用於識別資料庫裡面許多個表的唯一一個記錄.
第九大類:二進制碼字元串數據
binary:固定長度的二進制碼字元串欄位,最短為1,最長為8000.
varbinary:與binary差異為數據尾部是00時,varbinary會將其去掉
image:為可變長度的二進制碼字元串,最長2G.

3. sqlserver二進制日誌恢復

目前SqlServer沒有單表恢復,相對於oracle確實是一個不太方便的事情。
你可以將數據恢復到一個新資料庫,然後將誤刪的數據插入到目前A表中,這樣就不會影響其他數據了。

4. Sqlserver資料庫存儲的圖片格式(二進制數據)怎麼顯示到頁面

1.將圖片以二進制存入資料庫
//保存圖片到資料庫
protected void Button1_Click(object sender, EventArgs e)
{
//圖片路徑
string strPath = "~/photo/03.JPG";
string strPhotoPath = Server.MapPath(strPath);
//讀取圖片
FileStream fs = new System.IO.FileStream(strPhotoPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] photo = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
//存入
SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");
string strComm = " INSERT INTO personPhoto(personName, personPhotoPath, personPhoto) ";
strComm += " VALUES('wangwu', '" + strPath + "', @photoBinary )";
SqlCommand myComm = new SqlCommand(strComm, myConn);
myComm.Parameters.Add("@photoBinary", SqlDbType.Binary,photo.Length);
myComm.Parameters["@photoBinary"].Value = photo;
myConn.Open();
myComm.ExecuteNonQuery();
myConn.Close();
}
2.讀取二進制圖片在頁面顯示
//讀取圖片
SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");
string strComm = " SELECT personPhoto FROM personPhoto WHERE personName='wangwu' ";
SqlCommand myComm = new SqlCommand(strComm, myConn);
myConn.Open();
SqlDataReader dr = myComm.ExecuteReader();
while (dr.Read())
{
byte[] photo = (byte[])dr["personPhoto"];
this.Response.BinaryWrite(photo);
}
dr.Close();
myConn.Close();

SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");
SqlDataAdapter myda = new SqlDataAdapter(" SELECT personPhoto FROM personPhoto WHERE personName='11' ", myConn);
DataSet myds = new DataSet();
myConn.Open();
myda.Fill(myds);
myConn.Close();
byte[] photo = (byte[])myds.Tables[0].Rows[0]["personPhoto"];
this.Response.BinaryWrite(photo);
3.設置Image控制項顯示從資料庫中讀出的二進制圖片
---------------------------------------------
SqlConnection myConn = new SqlConnection("Data Source=192.168.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");
SqlDataAdapter myda = new SqlDataAdapter(" SELECT personPhoto FROM personPhoto WHERE personName='11' ", myConn);
DataSet myds = new DataSet();
myConn.Open();
myda.Fill(myds);
myConn.Close();
byte[] photo = (byte[])myds.Tables[0].Rows[0]["personPhoto"];
//圖片路徑
string strPath = "~/photo/wangwu.JPG";
string strPhotoPath = Server.MapPath(strPath);
//保存圖片文件
BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath,FileMode.OpenOrCreate));
bw.Write(photo);
bw.Close();
3.顯示圖片
this.Image1.ImageUrl = strPath;
4.GridView中ImageField以URL方式顯示圖片
--------------------------
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="personName" HeaderText="姓名" />
<asp:ImageField DataImageUrlField="personPhotoPath"
HeaderText="圖片">
</asp:ImageField>
</Columns>
</asp:GridView>
5.GridView顯示讀出的二進制圖片
//樣板列
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="personName" HeaderText="姓名" />
<asp:ImageField DataImageUrlField="personPhotoPath"
HeaderText="圖片">
</asp:ImageField>
<asp:TemplateField HeaderText="圖片">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex < 0)
return;
// System.ComponentModel.Container
string strPersonName = (string)DataBinder.Eval(e.Row.DataItem, "personName");
Image tmp_Image = (Image)e.Row.Cells[2].FindControl("Image1");
if (!System.Convert.IsDBNull(DataBinder.Eval(e.Row.DataItem, "personPhoto")))
{
//
byte[] photo = (byte[])DataBinder.Eval(e.Row.DataItem, "personPhoto");
//圖片路徑
string strPath = "~/photo/" + strPersonName.Trim() + ".JPG";
string strPhotoPath = Server.MapPath(strPath);
//保存圖片文件
BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath, FileMode.OpenOrCreate));
bw.Write(photo);
bw.Close();
//顯示圖片
tmp_Image.ImageUrl = strPath;
}
}

5. sqlserver插入語句報「將截斷字元串或二進制數據」怎麼解決,怎麼回事

INSERT 語句中, 字元串長度超過列的長度了。
下面是一個重現的例子:
表裡面 t 列長度為 varchar(10), 當你插入字元長度大於 10 的時候, 就要這個錯誤信息。

1> create table #test( t varchar(10) )
2> go

1> insert into #test values( '1234567890' )
2> go

(1 行受影響)

1> insert into #test values( '12345678901' )
2> go
消息 8152,級別 16,狀態 14,伺服器 TEST-PC\SQLEXPRESS,第 1 行
將截斷字元串或二進制數據。
語句已終止。
1>

6. sqlserver 直接輸入數據發生錯誤:截斷字元串或二進制數據

不要武斷地說沒有超出范圍。
還是要仔細查一下:
1、存儲過程變數定義精度或字元長度是否不足
2、表中的每一個欄位精度或字元長度是否不足
如果實在判斷不出來,可以通過逐一增加變數精度和字元變數長度的方法進行實驗,查出問題變數或欄位後再恢復。

7. 在SQL Server中,共使用了3種數據類型來存儲二進制數據,分別是______、______、

主要涉及 binary varbinary image 這三個欄位類型吧

請仔細了解sqlserver 各種數據類型

sql二進制數據類型詳解

如有疑問,及時溝通!

8. 我用來讀取sqlserver資料庫中二進制數據讀到文件中是這樣的

編碼格式問題吧
看你寫入資料庫用的什麼編碼格式了
如果ASCII:
string info = System.Text.Encoding.ASCII.GetString(data );
如果UTF8:
string info = System.Text.Encoding.UTF8.GetString(data );

然後再把info寫入文件中,就不用說了吧

9. 怎樣在sqlserver2008中用sql語句操作二進制數據

sqlserver之二進制和字元串sql語句
正常情況下我們對資料庫的操作就是如下的寫法來操作資料庫
SELECT TOP 10 ID AS 編號,BookName AS 書名 FROM dbo.books ORDER BY ID;

UPDATE dbo.books SET BookName='新的書名' WHERE ID=1233;

DELETE FROM dbo.books WHERE ID=122

但是在客戶正在使用的資料庫里,我們開發人員一般不能夠直接操作資料庫,但是會給我們做一個網頁以便方便我們核對數據,查找錯誤,但是這種情況下一般都會屏蔽一些關鍵詞,比如update delete,create,alter神馬的,一般請客下對客戶資料庫的操作都得嚴格按照公司流程來走,這種情況下效率一般都會很低,在這里還有一種情況可以直接讓我們對資料庫做更改,那就是首先將字元串以二進制的形式騙過後台程序,以便發送到資料庫中去執行,如下:
DECLARE @S NVARCHAR(4000)
SET @S=CAST( AS VARCHAR(max))
PRINT @S
EXEC(@S)

下面便是直接把sql語句轉換成二進制

DECLARE @str VARCHAR(MAX),@bary VARBINARY(MAX)
SET @str='SELECT TOP 10 ID AS 編號,BookName AS 書名 FROM dbo.books ORDER BY ID;'

--將字元串轉換成二進制對象
SET @bary= CAST(@str AS VARBINARY(MAX))
PRINT @bary

--將二進制對象轉換成字元串
SET @str=CAST(@bary AS VARCHAR(max))
--執行sql腳本
EXEC(@str)

10. sqlserver 二進制數據存儲問題

這種欄位我記得只要給個byte數組就可以了,不用轉移成binary

熱點內容
家用電腦改成伺服器並讓外網訪問 發布:2025-02-01 15:30:23 瀏覽:354
javac工資 發布:2025-02-01 15:24:28 瀏覽:22
如何刪除伺服器登錄賬號 發布:2025-02-01 15:21:05 瀏覽:498
瑞薩編程器 發布:2025-02-01 15:19:18 瀏覽:85
上海ntp伺服器搭建 發布:2025-02-01 15:03:38 瀏覽:991
c游戲編程基礎 發布:2025-02-01 15:00:17 瀏覽:993
routejs怎麼動態配置 發布:2025-02-01 14:59:07 瀏覽:502
家用電腦安裝伺服器內存 發布:2025-02-01 14:38:50 瀏覽:257
增量調制編解碼實驗報告 發布:2025-02-01 14:30:30 瀏覽:787
不良人2無敵傷害腳本 發布:2025-02-01 14:23:04 瀏覽:398