Sql server 2008 数据相加,但不在单个编译中显示
在VS2010中,我使用基于服务的数据库.mdf文件将名称和照片添加到我的数据库中。在调试并将数据添加到.mdf中之后,但在尝试检索数据时,它不会显示。它仅在下一次调试后显示。我真的被困在这两天了,请帮帮我 先谢谢你 我当前使用的连接字符串:Sql server 2008 数据相加,但不在单个编译中显示,sql-server-2008,visual-studio-2010,Sql Server 2008,Visual Studio 2010,在VS2010中,我使用基于服务的数据库.mdf文件将名称和照片添加到我的数据库中。在调试并将数据添加到.mdf中之后,但在尝试检索数据时,它不会显示。它仅在下一次调试后显示。我真的被困在这两天了,请帮帮我 先谢谢你 我当前使用的连接字符串: Dim path As String = (Microsoft.VisualBasic.Left(Application.StartupPath, Len(Application.StartupPath) - 9)) Dim con As New SqlC
Dim path As String = (Microsoft.VisualBasic.Left(Application.StartupPath, Len(Application.StartupPath) - 9))
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=" & path & "Database1.mdf;Integrated Security=True;User Instance=True")
这是我用来保存图像和名称的代码:
Dim cmd As New SqlCommand("INSERT INTO Information VALUES(@name,@photo)", con)
cmd.Parameters.AddWithValue("@name", TextBox1.Text)
Dim ms As New MemoryStream()
PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)
Dim data As Byte() = ms.GetBuffer()
Dim p As New SqlParameter("@photo", SqlDbType.Image)
p.Value = data
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery()
MessageBox.Show("Name & Image has been saved", "Save", MessageBoxButtons.OK)
这是我用来在datagridview中显示数据的代码
Me.InformationTableAdapter.Fill(Me.Database1DataSet.Information
你确定你像con.Open一样打开了SqlConnection吗?您能使用SqlDatareader并使用ExecuteReader读取您的数据吗?是的,我在表单加载时使用了con.open