Click here to Skip to main content
16,018,534 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I made a form in visual basic and I want to connect with sql connection I write the code to create database and tables and there are no errors but I have a message that appear sqlException was unhandled invalid object name "unc_tb" at the line of program (da.Fill(ds,"unc_tb") and the form in run mode don't appear
How can I solve this problem
Thanks in advance
Dalia
Posted
Comments
ACE_ 18-Dec-12 22:19pm    
Can you write your code before error line?
that error "unc_tb" has doesn't exists, please make sure you had that table
Rohit Shrivastava 19-Dec-12 18:45pm    
try to write the complete name like databasename.schema.tablename, mostly schema would be dbo.
Member 8697827 21-Dec-12 3:23am    
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim cn As SqlConnection
Dim ds As DataSet
Dim da As SqlDataAdapter
Dim r As DataRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strconnection As String = "data source=.\SqlExpress;initial catalog=master;integrated security=true"
cn = New SqlConnection(strconnection)
cn.Open()
Try
cn.ChangeDatabase("dd_db")
Catch ex As Exception
Try
Dim command As New SqlClient.SqlCommand("create database dd_db", cn)
command.ExecuteNonQuery()
command.Connection.ChangeDatabase("dd_db")
Dim command1 As New SqlClient.SqlCommand("create table dd_tb ([admi.num][int](10),[tran.num][int](4),[name][char](40),[age.reci][int](2),[sex.reci][char](8),[or.kid.d][char](22),[specify][char](50),[consang][char](20),[rec.b.g][char](8),[r_iggt][char](8),[r_iggr][char](12),[r_igmt][char](8),[r_igmr][char](12),[r_hcvt][char](8),[r_hcvr][char](12),[r_pcrt][char](8),[r_pcrr][char](12),[r_hbvt][char](8),[r_hbvr][char](12),[r_bpcrt][char](8),[r_bpcrr][char](12),[blood.gp][char](10),[rhla_aa][int](8),[rhla_ab][int](8),[rhla_ba][int](8),[rhla_bb][int](8),[rdr_a][int](8),[rdr_b][int](8),[prior.bl][char](8),[type.blo][char](15),[number.o][char](15),[num.bl.t][int](2),[datel.bl][date](10),[erythrop][char](8),[hypr_pre][char](8),[rec_schi][char](8),dia_rec][char](22),[sit_urn][char](12),[dial_pre][char](8),[dia_typ][char](20))", cn)
command1.ExecuteNonQuery()
Catch ex1 As Exception
MsgBox(ex.Message)
End Try
End Try
da = New SqlDataAdapter("select * from dd_tb", cn)
Dim x As New SqlCommandBuilder(da)
ds = New DataSet()
da.Fill(ds, "dd_tb")
End Sub
End Class

This is the code at the line of da.Fill(ds, "dd_tb") after compile it brings this message sqlException was unhandled invalid object name "unc_dd" I tried unc_dd.dbo.unc_dd but it brings the same message
So can you help me to find the solution
Thanks in advance
Dalia
Member 8697827 21-Dec-12 3:28am    
I also tried da.Fill(da) but the same message appear
so I remove this line the form appear But at button new to add new to the database it brings this message nullReferenceException was unhandled object reference not set to an instance of an object

1 solution

Take a look at Five different overloads of the DataAdapter.Fill() method[^] by http://www.codeproject.com/Members/Ravindra-T-C[^] and try da.Fill(ds) instead of da.Fill(ds, "dd_tb")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900